ProcessEvents CPU Using



  • Hi,

    Using QApplication::processEvents() in console applications uses lots of CPU , is there an other way to use handle timer isActive state? When I delete processEvents() routine it doesnt goes out from the loop.

    @
    timer_responseControl.setSingleShot(true);
    timer_responseControl.start(1000);
    while(timer_responseControl.isActive()){
    if(baudratedetectioncame){
    timer_responseControl.stop();
    baudratedetectionIsOk=1;
    }
    QApplication::processEvents();
    }
    @



  • CPU utilisation may be coming from while loop rather than ProcessEvents. Did you try commenting the processEvents and checked CPU utilisation. Why do you want while loop here ?



  • I solved problem with QEventLoop:
    just connect the packetcame signal to q quit slot.

    QEventloop q;
    timer_responseControl.setSingleShot(true);
    timer_responseControl.start(1000);
    q.exec();
    if(timer_responseControl.isActive()){
        if(rfresetcame){
            timer_responseControl.stop();
            rfresetIsOk=1;
            q.quit();
        }
    }


  • Another way you can look at is use two timers one with zero timer. Something like follows.

    @Widget::Widget(QWidget *parent)
    : QWidget(parent)
    {
    timer = new QTimer;
    timer->setInterval(1000);
    timer->setSingleShot(true);
    timer->start();
    connect(timer,SIGNAL(timeout()),this,SLOT(callme()));

    timer2 = new QTimer;
    timer2->setInterval(0);
    timer2->start();
    connect(timer2,SIGNAL(timeout()),this,SLOT(callme2()));
    

    }

    void Widget::callme() {
    qDebug() << " Call me" <<endl;
    timer->stop();
    }

    void Widget::callme2() {
    qDebug() << " Call me-2" <<endl;

    if (timer->isActive()){
        qDebug() << "Timer is still active" <<endl;
    }else {
        qDebug() << "Timer not active now" << endl;
    }
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.