使用 Qt 每个线程一个计时器

发布于 2024-09-02 20:21:22 字数 76 浏览 3 评论 0原文

我修改了Qt的广播发送器示例,使其具有十个线程,并且在每个线程中启动一个计时器,但仅触发第一个线程的计时器。如何为每个线程运行一个计时器?

I modified Qt's broadcast sender example so that it has ten threads and in each thread it starts a timer, but only timer of the first thread is triggered. How can I have one timer running for each thread?

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

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

发布评论

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

评论(2

呆橘 2024-09-09 20:21:22

计时器仅在线程具有事件循环时才起作用。

Timers only work if the thread has an event loop.

勿忘初心 2024-09-09 20:21:22

几年后,在操作系统课程中我学到了:
计时器是每个进程的东西。当操作系统内核发送计时器触发器时,即使当前正在运行的任何线程也会收到调用并处理它。
所以我不能以直接的方式为每个线程设置十个计时器。

A couple years later in OS course I learned:
Timers are a per process thing. When a the OS kernel sends a timer trigger even whatever thread that is currently running gets the call and processes it.
So I couldn't have ten timers per thread in a straight-forward manner.

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