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语句。

  • 相关阅读:
    协程与IO模型
    进程池与线程池
    GIL全局解释器锁
    线程编程
    进程编程
    基于UDP协议的socket
    异常处理
    jquery mobile外部js无法载入问题
    禁用或限制部分WebKit特性
    eval 返回变量值
  • 原文地址:https://www.cnblogs.com/findumars/p/5149581.html
Copyright © 2011-2022 走看看