PDA

View Full Version : QObject::timerEvent() time resolution



Halabund
19th April 2009, 18:00
It appears that on my system (WinXP, MinGW) the resolution of QTime::currentTime() is between 15 and 16 milliseconds.

The output of this increases in steps of 15 and 16:


QTime tt = QTime::currentTime();
for (;;) {
std::cout << tt.msecsTo(QTime::currentTime()) << std::endl;
}


I believe the resolution of intervals between QObject::timerEvent() calls to be the same (i.e ~15 ms).

I noticed this when I was using QObject::timerEvent() to draw the frames of an animation. I implemented the animation in Processing (http://processing.org/) earlier, and strangely the Processing version was running faster than the Qt version, even though the Qt version's CPU usage was always under 10%. It turns out that this is because the frame rates were not the same---because of the 15 ms resolution, in Qt I could only get frame rates of 1000/(N*15) with N=1,2,3,...

My question is: Is it possible to remedy this problem and have more precise frame rate control? Can I do anything to increase the resolution of Qt's timers? It is clearly possible to do more precise time measurements in Windows (the Java-based Processing appears to be able to do it), but is it possible to use them with Qt?

Halabund
21st April 2009, 09:32
I found the timeBeginPeriod (http://msdn.microsoft.com/en-us/library/ms713413(VS.85).aspx) and timeEndPeriod Windows functions, and tried calling them at the beginning and end of the main() function, but this seems to have no effect on the resolution of Qt timers. The resolution is still 15 ms. Does Qt use a timer that's unaffected by timeBeginPeriod, or was there something that I was doing wrong?