QThread Slots behavior

↘锁芯ラ 提交于 2019-12-11 18:06:54

问题


I am new to C++ and Qt and I am wondering what happens if I emit a signal in object1 running in thread1, to another object2 running in another thread2 and object2 is running an infinite loop for processing? Will the slot in object2 never be called since the thread2 is busy running the loop?


回答1:


I am new to C++ and Qt and I am wondering what happens if I emit a signal in object1 running in thread1, to another object2 running in another thread2 and object2 is running an infinite loop for processing? Will the slot in object2 never be called since the thread2 is busy running the loop?

Yes and no.

If you do not process events, then the thread will not chance to process the events, signals, and slots as you would expect.

However, you could make an event loop there that occasionally does process the events coming in, and then it would work as you expect it to.

My longer explanation than this is available here for people who would like to get more detailed information about the topic.



来源:https://stackoverflow.com/questions/20825039/qthread-slots-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!