Details
-
Task
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
(Not sure if we should update the documentation or something else, but creating anyway this ticket of my testing notes)
Qt Quick Timer documentation says "The Timer type is synchronized with the animation timer. Since the animation timer is usually set to 60fps, the resolution of Timer will be at best 16ms." (see https://doc.qt.io/qt-6/qml-qtqml-timer.html ). But this doesn't seem to be accurate: 16ms isn't the resolution, it is the minumum interval time. And it is only minimum when some animation is active.
Here is a simple tester application:
import QtQuick import QtQuick.Window Window { id: mainWindow property var time property int ticker: 0 property int ticker2: 0 width: 1400 height: 800 visible: true Timer { id: timer running: true repeat: true interval: 1 onTriggered: { if (ticker == 0) time = new Date().getTime(); ticker++ if (ticker >= 1000) { var time2 = new Date().getTime(); var duration = time2 - time; console.debug("Duration: " + duration + ", ticker: " + ticker + ", ticker2: " + ticker2); timer.running = false; } // Enable this in TEST2 //myRectangle.x += 1; } } Rectangle { id: myRectangle width: 100 height: 100 color: "red" /* // Enable also this in TEST3 NumberAnimation on rotation { running: timer.running loops: Animation.Infinite from: 0 to: 360 duration: 1000 } onRotationChanged: ticker2++; */ // Enable also this in TEST4 //visible: false } }
Results:
TEST1:
- interval 1: Duration: 1183, ticker: 1000, ticker2: 0
- interval 2: Duration: 2013, ticker: 1000, ticker2: 0
- interval 16: Duration: 15984, ticker: 1000, ticker2: 0
- interval 17: Duration: 16983, ticker: 1000, ticker2: 0
- interval 20: Duration: 19981, ticker: 1000, ticker2: 0
TEST2:
- interval 1: Duration: 3756, ticker: 1000, ticker2: 0
- interval 2: Duration: 5322, ticker: 1000, ticker2: 0
- interval 16: Duration: 16063, ticker: 1000, ticker2: 0
- interval 17: Duration: 16983, ticker: 1000, ticker2: 0
- interval 20: Duration: 19980, ticker: 1000, ticker2: 0
TEST3:
- interval 1: Duration: 16746, ticker: 1000, ticker2: 1000
- interval 2: Duration: 16714, ticker: 1000, ticker2: 1000
- interval 16: Duration: 16742, ticker: 1000, ticker2: 1000
- interval 17: Duration: 17058, ticker: 1000, ticker2: 1019
- interval 20: Duration: 20052, ticker: 1000, ticker2: 1199
TEST4:
- interval 1: Duration: 16738, ticker: 1000, ticker2: 1000
- interval 2: Duration: 16768, ticker: 1000, ticker2: 1000
- interval 16: Duration: 16746, ticker: 1000, ticker2: 1000
- interval 17: Duration: 17027, ticker: 1000, ticker2: 1019
- interval 20: Duration: 20070, ticker: 1000, ticker2: 1199
Conclusions:
- Timer is only synchronized with the (minimum) update refresh time when some animation is running. Without animations, timer with interval 1 is triggered ~ every 1ms.
- Timer triggering itself causing a scene update is not enough to syncronize it.
- Syncing is for animation, not screen refresh times, because hiding the animated element doesn't affect the results.
- When Timer interval is over 16.6ms, it is no longer tied to refresh time (meaning next trigger would come at 33.3ms). So when documentation states that resolution is 16ms, actually just minimum interval time is 16ms (with animations).