How can I run 3 QProcess in background using the same executable

前端 未结 1 1644
花落未央
花落未央 2021-01-27 18:14

I have a program that has a Worker class and this class has 3 QProcesses.

Each process will require a QDate as an argument. I want

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-27 18:37

    Your program freezes because it is busy all the time with waiting on QProcess to be finished, i.e. while(1). So, you do not return to the main event loop before all your dates are processed. If you wait long enough, your program will unfreeze.

    Different solutions exist:

    • Use the finished event to start processing a new date (until the list is empty), i.e. remove the infinite/waiting loop while(1).

    • Perform Worker::run in a separate thread.

    • Call QCoreApplication::processEvents to process the pending events, for example when has_available is false.

    Note that I prefer the first solution as Qt is an event driven system.

    0 讨论(0)
提交回复
热议问题