Qt connection type between threads: why does this work?

前端 未结 2 839
無奈伤痛
無奈伤痛 2021-01-20 00:55

While trying to make a multi-camera system work with a different thread handling a different camera, I couldn\'t get signals and slots working correctly between different th

相关标签:
2条回答
  • 2021-01-20 01:17

    I think I see what the issue might be.

    Your directConnection, which is really bad thing to do accross theads as it acts like an interrupt - executs immediatley. But it is BECAUSE it executes immediatley that it works in your case. When the thread closes down it emits the quit() signal.... then usually it "quits" but in direcetConnection it immediatley executes the slot finished() and then quits.

    If you have a QueuedConnection then it would emit the signal to the queue and then finish "quitting". However once the thread is stopped the thread queue is never servied so your finished() function is never run.

    Perhaps a better way to do this would be to connect to your object finished() send your signal there and then get the object within the thread to stop the thread itsself. (i.e. don't stop the thread remotly, stop the object, which in turn stops its thread).

    0 讨论(0)
  • 2021-01-20 01:18

    You moveToThread before connects that's why everything is in one thread.

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