Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Zero-second Timer doesn't run in qmlscene?



  • It looks like zero-second timers don't run using the qmlscene exe? The following snippet never prints anything.

    Rectangle {
    
        id: root
    
        Timer {
            interval: 0
            running: true
            repeat: true
            onTriggered: {
                print('here')
            }
        }
    }
    

  • Moderators

    @patrickkidd
    I can't say for sure, but the documentation states:

    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.
    

    so any interval < 16 doesn't make much sense to begin with.



  • @patrickkidd said in Zero-second Timer doesn't run in qmlscene?:

    interval: 0

    if you need to Trigger immediately, QML Timer has triggeredOnStart bool property you can set to true for the first tick,
    otherwise an interval of 0ms makes absolutely no sense



  • The code does work, but you need to omit "interval: 0", then it prints in console; "qml: here"



  • @J-Hilk

    so any interval < 16 doesn't make much sense to begin with.

    Thanks for pointing that out, as it helps in the case that someone is attempting to optimize performance in animations.

    @LeLev

    if you need to Trigger immediately, QML Timer has triggeredOnStart bool property you can set to true for the first tick,
    otherwise an interval of 0ms makes absolutely no sense

    A zero-second timer would be used for wanting something to execute whenever there is idle time in the event loop. This would obviously lock a graphical application, but can be used effectively in short bursts or for discrete worker tasks, or simply to queue a one-off update after the current GUI job is done for example when you want to initialize a component after onCompleted is finished. In these cases you managing the running property to start and top the timer but leave the interval at 0. This is a common use case, especially when there are a lot of bugs in the built-in Qml types (which is often the case) and you are trying to workaround them. triggeredOnStart does not accomplish this as it starts the timer in the same call as setting running = true.


Log in to reply