CPU满格的元凶,这回是由于QTimer引起的(默认interval是0,太猛)

timer_space = new QTimer();
qDebug() << SystemGlobal::m_app->SpaceUse;
qDebug() << timer_space->interval();
if (!SystemGlobal::m_app->SpaceUse>=95) {
timer_space->setInterval(60*60*1000); // 每小时提醒一次
connect(timer_space, SIGNAL(timeout()), this, SLOT(SpaceError()));
}
//timer_space->start();

我把start()屏蔽后,CPU立刻降了下来。查找说明文档一看:

interval : int

This property holds the timeout interval in milliseconds.

The default value for this property is 0. A QTimer with a timeout interval of 0 will time out as soon as all the events in the window system's event queue have been processed.

结果发现自己忘了手动设置interval。

-----------------------------------------------------------

另外,我这个表达式也有错误,应该写成:

    if (!(SystemGlobal::m_app->SpaceUse>=95)) 

此时单步执行可以进入if语句。按照原来的写法,直接跳过if语句。

原文地址:https://www.cnblogs.com/findumars/p/5149581.html