QML Timer - How to improve accuracy?

亡梦爱人 提交于 2019-12-31 01:48:08

问题


I'm developing a QML metronome. I used a timer with interval 60000/Beats per minute. However it isn't really accurate. How can I improve the accuracy. Should I use a Timer, or is there a better solution?


回答1:


The fundamental issue with QTimer that it uses the Qt event loop for the timing. Unfortunately, it cannot be accurate enough, inherently. The latency for notifications and all that within the event loop is getting in the way.

You would need to consider a timer that does not actually depend highly on the Qt event loop, like QueryPerformanceCounter() on Windows. That is how we get to the realm of QElapsedTimer.

Thereby, I would use QElapsedTimer for this purpose.

The following post has a custom class implemented for this purpose as it seems. You may be able to take it as is, and then tweak it to suit your need even better if needed.

High Resolution Timer



来源:https://stackoverflow.com/questions/21065975/qml-timer-how-to-improve-accuracy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!