从其他线程发出信号
我有一个类,它有一个由主线程和其他 3 个线程(2 个 QThreads 和 1 个用 QtConcurrent::run() 创建的)调用的方法。在这个方法中我有时会发出一个信号。这可以吗,或者可能会导致问题,因为我没有发出属于调用线程的信号。
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 emitting signals that belong to the calling threads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这完全没问题。 QT 透明地为您进行线程间通信。如果需要触发的槽位于另一个线程中,则信号将排队,并在目标线程进入其事件循环时被接收。
您可以尝试一下,看看调试器中会发生什么。
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.