开发者

Emitting signals from other threads

开发者 https://www.devze.com 2022-12-18 20:17 出处:网络
I have a class which has a method that is called by the main thread and 3 other threads (2 QThreads and 1 made with QtConcurrent::run()).Inside this method I sometimes emit a signal.Is this okay or co

I have a class which has a method that is called by the main thread and 3 other threads (2 QThreads and 1 made with QtConcurrent::run()). Inside this method I sometimes emit a signal. Is this okay or could it cause problems since I am not emittin开发者_C百科g signals that belong to the calling threads.


Yes, this is perfectly ok. QT does the inter-thread communication for you transparently. If the slot that needs to fire is in another thread then the signal gets queued and will be received by the destination thread when it enters its event loop.

You can try it and see what happens in a debugger.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号