Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to find the duration of a loop running.
Forum Updated to NodeBB v4.3 + New Features

How to find the duration of a loop running.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 352 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JennyAug13
    wrote on 12 Feb 2019, 11:33 last edited by JennyAug13 2 Dec 2019, 11:34
    #1

    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.

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

    Thanks in advance.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 13 Feb 2019, 05:32 last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      1
      • S Offline
        S Offline
        SeeLook
        wrote on 13 Feb 2019, 10:23 last edited by SeeLook
        #3

        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
              }
            }
        }
        
        1 Reply Last reply
        1

        1/3

        12 Feb 2019, 11:33

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved