另一个应用程序用 c++ 在 Windows 上的线程中破坏 QTimer
Another application breaks QTimer in thread on Windows with c++
我有自己的小框架(serial_port
下面(通过QSerialPort发送/获取消息。这是我如何从另一个线程开始的:
serial_port->moveToThread(connection_thread);
serial_port->serial->moveToThread(connection_thread);
serial_port->timer->moveToThread(connection_thread);
然后我连接信号:
connect(connection_thread, SIGNAL(started()), serial_port, SLOT(start_loop()));
connect(serial_port, SIGNAL(finished()), connection_thread, SLOT(quit()));
connect(connection_thread, SIGNAL(finished()), serial_port, SLOT(deleteLater()));
connect(serial_port, SIGNAL(finished()), connection_thread, SLOT(deleteLater()));
在serial_port
中,QTimer 发送超时消息:
connect(timer, SIGNAL(timeout()), this, SLOT(send_message()));
我的问题是另一个程序在QTimer
开始工作后运行,正在破坏这个计时器。它发生在大约 20% 的病例中。问题包括获得信号timeout()
比预期的要快得多。它发生在Windows平台上,但对于Linux来说一切都很好。我在哪里可以找到问题的原因?
尝试使用这个:
-
connection_thread->setPriority(QThread::HighestPriority);
或
-
connection_thread->setPriority(QThread::TimeCriticalPriority);
使计划更频繁。
和
-
serial_port->timer->setTimerType(Qt::PreciseTimer)
使QTimer
成为PriciseTimer
类型。
希望对您有所帮助。
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 在C++中使用cURL和多线程
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在cuda线程之间共享大量常量数据
- 如何将元素添加到数组的线程安全函数?
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 异常属于C++中的线程还是进程
- C++中的线程安全删除
- C++使用params创建线程函数会导致转换错误
- 类与私有变量的其他类之间的线程安全性
- CoInitialize()在单独的线程上崩溃而不返回
- c++中的线程池
- 线程之间的布尔停止信号
- 另一个应用程序用 c++ 在 Windows 上的线程中破坏 QTimer
- QTimer 线程的方法 'isActive()' 是安全的吗?
- QTimer对象是否在单独的线程中运行?它的机制是什么
- 我可以使用QTimer实现多线程算法