C++/Qt - QThread vs QRunnable

前端 未结 3 2072
广开言路
广开言路 2020-12-29 09:03

What are the differences between QThreads and QRunnable ?

When should I use QThread and when QRunnable ?

3条回答
  •  情深已故
    2020-12-29 09:58

    Choosing between using QThreadPool and QThread
    The Qt framework offers many tools for multithreading. Picking the right tool can be challenging at first, but in fact, the decision tree consists of just two options: you either want Qt to manage the threads for you, or you want to manage the threads by yourself. However, there are other important criteria:

    Tasks that don’t need the event loop. Specifically, the tasks that are not using signal/slot mechanism during the task execution. Use: QtConcurrent and QThreadPool + QRunnable.

    Tasks that use signal/slots and therefore need the event loop. Use: Worker objects moved to + QThread.

    Refer the link for detailed description: nice read on qt threading

提交回复
热议问题