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. QTimer restart increasing CPU usage

QTimer restart increasing CPU usage

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.5k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    marcosbontempo
    wrote on last edited by
    #1

    Hello,

    I need to reset a QTimer every time the touchscreen of a display is pressed. I'm using this command to reset the timer:

    timer->start(interval*1000*60);
    

    But every time I touch the display the CPU usage of the programa increases. Does anybody know how to correct it? After some time using the program, the CPU usage gets 100%;

    Any tip will be very helpful,
    Thanks.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      from one line of code its hard to give guesses.

      Do you create a new timer each time you "touch" ?

      The function that is called when timeout happens, what are you doing in there?`
      Do you have loops ?

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        hi
        from one line of code its hard to give guesses.

        Do you create a new timer each time you "touch" ?

        The function that is called when timeout happens, what are you doing in there?`
        Do you have loops ?

        M Offline
        M Offline
        marcosbontempo
        wrote on last edited by
        #3

        @mrjj

        I use the same timer.

        I don't have loops in the function that is called when timeout happens.

        When I press the touchscreen, this function is executed:

        void TimeControl::restartTimeCounter(int timeoutType)
        {
            // Restart timer:
            int interval = qdbc->generalconfig->getConfigurationInt(CONFIGURATION_ATTRIBUTE_DISPLAY_IDLE_TIME);
            timer->stop();
            timer->start(interval*1000*60); // LINHA QUE CAUSA O AUMENTO DE CPU
        
            switch(timeoutType)
            {
                case 1: // Display control
                    if(display == false)
                    {
                        display = true;
                        turnOnDisplay();
                    }
                break;
            }
        }
        

        This is the function that is called when timeout happens:

        void TimeControl::turnOnDisplay()
        {
            QFile backlight_file(backlight);
        
            int action = qdbc->generalconfig->getConfigurationInt(CONFIGURATION_ATTRIBUTE_DISPLAY_ACTION);
        
            if(display)
            {
                switch(action)
                {
                    case PhotoFrame:
                        // Stop photoframe
                        qdbc->photoframe->stopPhotoframe();
                    break;
                    case Brightness:
                        // Turn on display
                        QString brightness = qdbc->generalconfig->getConfigurationString(CONFIGURATION_ATTRIBUTE_DISPLAY_BRIGHTNESS);
                        if(backlight_file.open(QFile::WriteOnly | QFile::Truncate)){
                            backlight_file.reset();
                            QTextStream back(&backlight_file);
                            back << brightness;
                        }
                        backlight_file.close();
                    break;
                }
        
                display = true;
            }
            else
            {
                switch(action)
                {
                    case PhotoFrame:
                        // Run Photoframe
                        qdbc->photoframe->runPhotoframe();
                    break;
                    case Brightness:
                        // Turn off display
                        if(backlight_file.open(QFile::WriteOnly | QFile::Truncate)){
                            backlight_file.reset();
                            QTextStream back(&backlight_file);
                            back << "0";
                            qdbc->callreceived->closeGUI();
                        }
                        backlight_file.close();
                    break;
                    case MainPage:
                        // Return to main page
                        qdbc->callreceived->closeGUI();
                    break;
                }
        
                display = false;
            }
        }
        
        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          hmm.
          It dont really look heavy.
          I wonder if qdbc->photoframe->runPhotoframe();
          could be the heavy one?

          M 1 Reply Last reply
          0
          • mrjjM mrjj

            hmm.
            It dont really look heavy.
            I wonder if qdbc->photoframe->runPhotoframe();
            could be the heavy one?

            M Offline
            M Offline
            marcosbontempo
            wrote on last edited by
            #5

            @mrjj

            Thanks for your answer!

            I commented all the content of the function that is called when timeout happens (turnOnDisplay). However, the CPU usage increasing still continues. The only line that is beeing called is

            timer->start(interval*1000*60);
            
            
            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              What is your OS and your version of Qt?

              What are the usual values of interval?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              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