Pergunta

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?

Foi útil?

Solução

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?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top