Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ProcessEvents CPU Using
QtWS25 Last Chance

ProcessEvents CPU Using

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umtkyck
    wrote on last edited by
    #1

    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();
    }
    @

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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 ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umtkyck
        wrote on last edited by
        #3

        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();
            }
        }
        
        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          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;
          }
          

          }
          @

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved