繁体   English   中英

另一个应用程序使用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类型。

希望它能帮到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM