Important: Please read the Qt Code of Conduct -

How to find the duration of a loop running.

  • Hi, how can i find the duration of my for loop using a timer in qml? So that, i want to stop another parallel process for that duration of time.

    I found following examples on timer on internet.

            id: visibilityCheckTimer
            running: false
            repeat: false
            property var callBack
            onTriggered: callBack()
        function setTimeout(callback, delay)
              console.log("nested calls to setTimeout are not supported");
            visibilityCheckTimer.callBack = callback;
            timer.interval = delay + 1;
            timer.running = true;

    Thanks in advance.

  • Moderators

    There is no API for getting elapsed time of a loop. You'd need to use another Timer component to measure the running time.

  • Hi,

    What if use Date().getTime() to obtain current time in ms, then compare it in next Timer loop?

    Timer {
        id: timer
        repeat: true
        property real prevTime: 0
        onTriggered: {
          var currTime = new Date().getTime()
          if (prevTime > 0) { // skip first loop
            console.log("timer loop took",  currTime - prevTime + "[ms]")
            prevTime = currTime

Log in to reply