View Full Version : QTimer resolution.

18th January 2010, 13:45
Hi, i am using QTimer in my application to set the frecuency of my main loop, and trying to set the FPS of my app.
First, ill post the values i put in setInterval(), and the values i get between elapsed():

setInterval() - elapsed()
1 ------------- 1
2 ------------- 2
3 ------------- 3
... ----------- ...
19 ----------- 19
20 ----------- 20

21..31 --------- 31

32..46 --------- 46

47..62 --------- 62


I know windows have a resolution of 15.625 ms, and the results from 20 miliseconds work as expected, but under 20ms, its gives a nice 1ms resolution, so i guess QTimer uses another implementation (Multimedia timers??) when you set the interval under 20ms. I have also noticed that CPU is higher under 20 ms and drops to nearly 0 after 21 ms, so this would confirm that the more demanding multimedia timers are used.

I hope we can clarify this, as QTimer documentation is very short for this...

18th January 2010, 14:00
Ive found this in the changelog of 4.6 (which im using). This confirms that MM timers are used below 20ms

- QEventDispatcherWin32 (internal class)
90 * Changed the threshold for using multimedia timers to 20ms (was 10ms).

Now the question is how to change it so QTimer can be used like a multimedia timer to get linear FPS in our loops...

19th January 2010, 20:10
Ive implemented my own Multimedia timer, so i can get any framerate i want, (well, any 1000/integer interval). I hope Qt devs add the option to set the threshold for QTimer to use Multimedia timers, so you dont have to use platform-specific timers.

31st March 2010, 20:08
Wow, thanks for the finding and posting it here!

I was wondering why the sudden CPU usage when I changed the interval. I am glad the MM timers are used when needed.
I also wish the document were more clear on that.