QML计时器 - 如何提高准确性? [英] QML Timer - How to improve accuracy?

查看:558
本文介绍了QML计时器 - 如何提高准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个QML节拍器。我使用一个定时器间隔60000 /每分钟节拍。但是它不是真的准确。如何提高准确度。我应该使用定时器,还是有更好的解决方案?

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?

推荐答案

QTimer的基本问题是它使用Qt事件循环进行计时。不幸的是,它本质上不够准确。通知延迟和事件循环中的所有延迟都会受到影响。

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.

您需要考虑一个实际上不会严重依赖Qt事件循环的计时器,例如Windows上的 QueryPerformanceCounter()这是我们如何到达QElapsedTimer的范围。

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.

因此,我将使用 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.

高分辨率计时器

这篇关于QML计时器 - 如何提高准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆