在现有的非 QT 线程中创建 QThread 事件循环

发布于 2024-09-09 07:55:28 字数 233 浏览 1 评论 0原文

我的代码是主机软件的插件,其处理时间有限。因此,我创建了第二个线程(通过系统 API)并在那里启动 QApplication。这样,GUI 就可以顺利运行。

现在,我想在原始版本中运行 QThread 事件循环,以便我可以使用 Signal/Slot (Qt::QueuedConnection) 来调用主机软件中非线程安全的函数。

有没有办法创建这样的 QThread 事件循环而不创建新线程?

谢谢!

My code is a plugin of a host software which gets limited processing time. Therefore, I create a second thread (via system API) and start QApplication there. That way, the GUI runs smoothly.

Now, I would like to run a QThread event loop in the original such that I could use Signal/Slot (Qt::QueuedConnection) to invoke functions that are not thread safe in the host software.

Is there a way to create such QThread event loop without creating a new thread?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

怀念你的温柔 2024-09-16 07:55:28

我不确定我是否理解对了你
但是您可以通过在私有类成员上调用 QEventLoop::exec() 来启动自己的事件循环。

不要忘记调用 QEventLoop.exit()。

再见,拉尔斯

I'm not quit sure if i get you right,
but you can start your own event loop just by calling QEventLoop::exec() on a e.g. private class member.

Don't forget to call QEventLoop.exit().

Bye, Lars

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