从其他线程发出信号

发布于 2024-08-19 20:00:51 字数 130 浏览 4 评论 0原文

我有一个类,它有一个由主线程和其他 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2024-08-26 20:00:51

是的,这完全没问题。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文