Unsolved QTimer restart increasing CPU usage
-
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. -
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 ? -
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; } }
-
hmm.
It dont really look heavy.
I wonder if qdbc->photoframe->runPhotoframe();
could be the heavy one? -
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);
-
What is your OS and your version of Qt?
What are the usual values of
interval
?