QML Timer - How to improve accuracy?

I am developing a QML metronome. I used a timer at intervals of 60,000 / beats per minute. However, this is not very accurate. How to increase accuracy. Should I use a timer or is there a better solution?

+4
source share
1 answer

The main problem with QTimer is that it uses the Qt event loop for synchronization. Unfortunately, it may not be sufficiently accurate, in fact. The delay for notifications and everything in the event loop interferes.

You will need to consider a timer, which is actually not very dependent on the Qt event loop, for example QueryPerformanceCounter()on Windows. This is how we get to the kingdom of QElapsedTimer.

Thus, I would use QElapsedTimer for this purpose.

The following post has a custom class implemented for this purpose, as it seems. You can take it as it is, and then customize it to your needs even better if necessary.

High resolution timer

+3
source

All Articles