QWidgets Application - High CPU Usage

  • I've noticed over the past few days that my QWidgets application seems to have pretty high CPU usage and I really can't understand why or what is causing this high CPU usage.

    Looking at Task Manager in Windows 10, when the application is idle, nearly 50% of the CPU time is being used by my application. When I say my application is idle, literally nothing is going on - no threads running, no displays updating, nothing. If I pause the debugger, it hits the following line in main.cpp:

    QApplication a(argc, argv);
    // Initialize my application state here...
    MainWindow w;
    return a.exec();

    When I "initialize my application state", I load in a settings file using QSettings, prepare a few variables and call a few functions but then the application shows the MainWindow before going idle while waiting for the user to click a "connect" button which hooks up a number of threads, etc and connects to various hardware devices via QSerialPorts. At the time of checking the high CPU time, none of this has happened.

    What debugging features available in Qt Creator can help me figure out what is going on? This seems really unusual behaviour.


  • Lifetime Qt Champion


    Callgrind could be used and you might want to also take a look at KDAB's HotSpot project.

    Hope it helps

  • @SGaist Thanks, although I don't seem to be able to get callgrind to work.

    When I follow the instructions, select "callgrind" from the drop-down and click "Start analysis", nothing happens...

  • @webzoid For Valgrind integration with Qt Creator, take a look at this.
    However, most of the Valgrind tool set is intended to be run under Linux, and you have mentioned Windows 10... Is it possible for you to run your application under Linux? at least to check if it behaves the same and in such case to go ahead with profiling session.

  • @Pablo-J.-Rogina Unfortunately I don't have access to a Linux machine. There is scope to set up an Ubuntu VM however I've only got a small SSD in my laptop and it would mean clearing the way somehow.

    I think I'll just have to do it the old fashioned blood-and-thunder way using qDebug() statements.

  • Having said that the application is idle, there is some QML loaded in at this point into a QQuickWidget - would the rendering loop for this cause high CPU usage?

Log in to reply

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