QTimer and performance on Windows

  • I have a Qt application that exhibits dramatically different performance on Windows (7) and Mac OS X, on the same machine (i7 iMac). It's fairly simple - displays a 3D model using OpenGL, using a subclassed QGLWidget...nothing fancy. For various reasons, its GUI (buttons, sliders, etc.) are home-grown using OpenGL rectangles and custom GLSL shaders.

    In order for things like "hover highlighting" to work with these GUI elements, we use a QTimer set with a value such that we get timer events at a rate equivalent to 30fps.

    I see a dramatic performance deficit on the Windows version of the app (40% or so slower). This is on the same machine, but of course we're talking different OpenGL drivers, different compilers, different C++ runtime, different OS and window system, etc. So, there could be many causes of the difference. But, on other Qt OpenGL-using apps (that don't use QTimers), I don't recall seeing such a performance difference...

    However, in poking around, I've seen a lot of issues with QTimer on Windows mentioned. Could the performance diff be due (in part) to issues with QTimer on Windows? If so, can anything be done?

    Sorry to provide such a nebulous description, but I'm hoping that this behavior sounds familiar to someone (and of course that they'll have a remedy :-)


  • What code do you use ? Do you use something like :

    QTimer *timer = new QTimer(this);
    timer->setInterval(1000 / 30);

    Maybe for having perfect 30 FPS, it is better to consider

    QGLWidget *widget = new QGLWidget(this);
    QGLFormat format = QGLFormat();
    format.setSwapInterval(2); // Force drawing each 2 buffer swap

    It will block rendering thread on VSync, and if your screen is 60Hz, drawing each 2 buffer swaps will give 30FPS.

    Then, try to use


    This will tell the timer to tick when the event loop is finished. But since the rendering is blocked for 30FPS, the event loop will also block and then it will tick at 30FPS, aligned on VSync.

    This might fix the QTimer performances issues (as a workaround)

Log in to reply

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