Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    ProcessEvents CPU Using

    General and Desktop
    2
    4
    1293
    Loading More Posts
    • 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
      umtkyck last edited by

      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 Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        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 Reply Quote 0
        • U
          umtkyck last edited by

          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 Reply Quote 0
          • dheerendra
            dheerendra Qt Champions 2022 last edited by

            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 Reply Quote 0
            • First post
              Last post