Stop Qt Thread : calling exit() or quit() does not stop the thread execution

后端 未结 3 1144
野的像风
野的像风 2021-01-19 01:10

Created a QThread in main() i.e Main thread. Moved a worker class to the new thread. The thread executes the \'StartThread\' method of worker class.

Worker Thread:

3条回答
  •  耶瑟儿~
    2021-01-19 01:44

    You declared and initialized count inside the while loop. Move it outside and it will stop reinitializing to zero every iteration, and thus quit on time. I'm unclear why you've declared it static, as well.

    Note
    If you intend to use queued signals and handle events, make sure you periodically call processEvents on the thread's event dispatcher inside your while loop:

    if (thread()->eventDispatcher()->hasPendingEvents()
        thread()->eventDispatcher()->processEvents();
    

提交回复
热议问题