zoukankan      html  css  js  c++  java
  • 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语句。

  • 相关阅读:
    mysql多表关系
    mysql支持的数据类型
    数据库基本操作
    线程基础
    生产者和消费者模型
    并发编程一
    元类
    linux 关机/重启命令
    linux前后台任务切换
    centos7最小化安装后,yum安装pstree及mlocate
  • 原文地址:https://www.cnblogs.com/findumars/p/5149581.html
Copyright © 2011-2022 走看看