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. Need a Timer which works exactly

Need a Timer which works exactly

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 1.9k Views
  • 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.
  • S Offline
    S Offline
    Snoopy
    wrote on last edited by
    #1

    Hello,
    I need a Timer which works really exactly. Has somebody an idea ?
    In my application there is the usecase to change an Image in a constant intervall with another one. For example every 100 ms.
    Okay. There is the QML Timer.

    But this Timer doesn't work independent from the running application and so the Timer never works exactly. If I do something more at the same time (scrolling a listview, moving the mouse) it gets really bad.

    JKSHJ 1 Reply Last reply
    0
    • S Snoopy

      Hello,
      I need a Timer which works really exactly. Has somebody an idea ?
      In my application there is the usecase to change an Image in a constant intervall with another one. For example every 100 ms.
      Okay. There is the QML Timer.

      But this Timer doesn't work independent from the running application and so the Timer never works exactly. If I do something more at the same time (scrolling a listview, moving the mouse) it gets really bad.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Snoopy said in Need a Timer which works exactly:

      In my application there is the usecase to change an Image in a constant intervall with another one. For example every 100 ms.

      For this use-case, it is best not to use a timer to trigger image loading.

      Ideally, all your images should be combined into one file (e.g. an animated GIF file or a sprite file), and played with AnimatedImage (QML), AnimatedSprite (QML), or QMovie (widgets).

      Anyway:

      1. How big are your images?
      2. What is your code for changing the images?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Snoopy
        wrote on last edited by
        #3

        Thanks for the info. I will check it.

        One image has 300 x 300 Pixels and format is actually PNG. Size of one image is 20 KB.
        In the worstcase in one run I've to show 120 images. For example every 100 ms the next one.

        Below the code how I do it at the moment.

            Timer {
                id:timer
                   interval: 100;
                   running: false;
                   property int ix: 0
        
                   onTriggered:
                   {
                       if (ix == 120)
                           timer.stop();
                        else
                      {
                       ix++;
        
                       myControl.step = ix;
                       running = true;
                    }
          }
        

        Item{
        id: myControl
        property int step: 0

        Image
        {
            id: image
            source: "images/Step" + myControl.step + ".png"
            visible: true
            cache: true
        }
        

        }

        JKSHJ 1 Reply Last reply
        0
        • S Snoopy

          Thanks for the info. I will check it.

          One image has 300 x 300 Pixels and format is actually PNG. Size of one image is 20 KB.
          In the worstcase in one run I've to show 120 images. For example every 100 ms the next one.

          Below the code how I do it at the moment.

              Timer {
                  id:timer
                     interval: 100;
                     running: false;
                     property int ix: 0
          
                     onTriggered:
                     {
                         if (ix == 120)
                             timer.stop();
                          else
                        {
                         ix++;
          
                         myControl.step = ix;
                         running = true;
                      }
            }
          

          Item{
          id: myControl
          property int step: 0

          Image
          {
              id: image
              source: "images/Step" + myControl.step + ".png"
              visible: true
              cache: true
          }
          

          }

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @Snoopy said in Need a Timer which works exactly:

          One image has 300 x 300 Pixels and format is actually PNG. Size of one image is 20 KB.
          In the worstcase in one run I've to show 120 images. For example every 100 ms the next one.

          You could merge the 120 images into one large PNG sprite grid (12 x 10 images = 3600 x 3000 pixels), and display it using an AnimatedSprite.

          Or, you could merge the images into 1 animated GIF or 1 animated MNG, and display it using AnimatedImage.

          Image
          {
              source: "images/Step" + myControl.step + ".png"
          }
          

          Your code starts loading each image when the timer triggers. So, this is the sequence:

          1. Wait for timer to trigger
          2. Load image from disk
          3. Display image
          4. Goto #1

          Step #2 is very slow. If you can find a way to load the images into memory before you start the timer, you might see better performance.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          1
          • S Offline
            S Offline
            Snoopy
            wrote on last edited by
            #5

            Okay thanks for the answer.

            But how can I set the interval in the AnimatedSprite ? I want to replace an image with the next one everytime after 100 ms.
            If I want to run the AnimatedSprite with another interval for example 250 ms or 500 ms. How can I do that ?

            J.HilkJ 1 Reply Last reply
            0
            • S Snoopy

              Okay thanks for the answer.

              But how can I set the interval in the AnimatedSprite ? I want to replace an image with the next one everytime after 100 ms.
              If I want to run the AnimatedSprite with another interval for example 250 ms or 500 ms. How can I do that ?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Snoopy without having it tested:

              AnimatedImage has the properties:

              currentFrame : int
              frameCount : int
              paused : bool
              playing : bool

              so:

              paused: true
              currentFrame: myControl.step
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                In addition to @J-Hilk's properties, there's also frameRate or frameDuration: http://doc.qt.io/qt-5/qml-qtquick-animatedsprite.html#frameDuration-prop

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                3

                • Login

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