首页 > 其他 > 详细

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

时间:2016-01-21 23:07:00      阅读:273      评论:0      收藏: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语句。

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

原文:http://www.cnblogs.com/findumars/p/5149581.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!