Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTimer not accurate at all?

Tags:

c++

qt

Running on Windows7 64bit machine with a very powerful CPU (8 core 16 threads). I used a QTimer to trigger a function call at 50Hz. But I ended up with 30Hz. The function call itself definitely takes less than 10ms to finish. The whole process happens in a separate thread.

What could go wrong in my case? The Qt's doc said it will be accurate within 5%?

like image 972
Nyaruko Avatar asked Feb 23 '17 16:02

Nyaruko


1 Answers

You can achieve a better timer precision by setting timer type property to Qt::PreciseTimer (the default type is Qt::CoarseTimer).

From the docs:

Qt::PreciseTimer – Precise timers try to keep millisecond accuracy.
Qt::CoarseTimer – Coarse timers try to keep accuracy within 5% of the desired interval.

However, as pointed out by @Paul and @AlgirdasPreidžius, there is still no guarantee that the precision will be perfectly accurate.

like image 185
kefir500 Avatar answered Sep 28 '22 03:09

kefir500