0

I've read here about the possibility to improve timers accuracy in QML exploiting QElapsedTimer instead of a simple QTimer (which is based on QT event loop) but it is not clear to me how I can do that...

Is there somebody that can help me in providing a full example?

Community
  • 1
  • 1
Morix Dev
  • 2,700
  • 1
  • 28
  • 49
  • 1
    What is the problem that you're trying to solve? – Kuba hasn't forgotten Monica Apr 07 '14 at 17:14
  • I am trying to have the smoothest possible animation of some objects on screen... using QML element `Animation` or some javascript in a standard `Timer` callback it is good, but not perfect... sometimes the animation is not naturally fluid... printing to console the date/time at every timer tick it seems that timer callback is not regularly called, and this is where my question originated. Am I on the wrong way? Is there something that I am missing about that? – Morix Dev Apr 07 '14 at 20:10
  • There's not much you can do here - the operating system is the source of the tick. The best you can do is use the tick whenever it comes, but calculate the position based on real time from `getTime`. This assumes that `Animation` doesn't already do just that. – Kuba hasn't forgotten Monica Apr 07 '14 at 20:15

1 Answers1

2

QElapsedTimer is a means of measuring the time. It doesn't provide a way of returning control to your code when a given amount of time elapses, since it doesn't have any blocking methods. It also doesn't have any signals/callbacks.

The only way of using a QElapsedTimer to provide accurate interval timing is to spin: in a tight loop you keep checking the timer until a given amount of time has passed, then you continue with execution of your code. Unless it would be used sparingly - say only during application startup - this has horrible impact on battery life and energy consumption. It's a hack that has very specific uses and is not needed in ordinary QML code.

What is the problem that you're trying to solve?

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313