What happens to the thread affinity of a QObject created within a worker thread which then terminates?

后端 未结 6 763
庸人自扰
庸人自扰 2021-02-05 04:39

Let\'s say I call QtConcurrent::run() which runs a function in a worker thread, and in that function I dynamically allocate several QObjects (for later use). Since

6条回答
  •  死守一世寂寞
    2021-02-05 05:13

    I am not sure if Qt automatically change the thread affinity. But even if it does, the only reasonable thread to move to is the main thread. I would push them at the end of the threaded function myself.

    myObject->moveToThread(QApplication::instance()->thread());
    

    Now this only matters if the objects make use of event process like send and receive signals.

提交回复
热议问题