今天用QObject的startTimer()函数启动定时器,结果爆出了下面的错误:
QObject::startTimer: Timers can only be used with threads started with QThread
通过分析发现,Timer启动必须从线程开始启动。下面是我的代码:
TestTypeClass::TestTypeClass()
{
timerId = this->startTimer(1000);
qDebug()<<timerId<<endl;

本文介绍了在Qt中使用QObject的startTimer()函数时遇到的一个常见错误:无法在非QThread启动的线程中使用定时器。文章通过示例代码详细解释了如何调整程序结构以避免该错误,并给出了正确的实现方式。
最低0.47元/天 解锁文章
1117

被折叠的 条评论
为什么被折叠?



