Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qtimer Behaviour
Forum Update on Monday, May 27th 2025

Qtimer Behaviour

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 703 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.
  • Y Offline
    Y Offline
    yuvalg1987
    wrote on last edited by
    #1

    Hi,

    I developing a simple image processing software and wanted to clarify the behaviour of Qtimer. For the sake of the discussion, let’s say that the timer's interval will be set to 30ms while the attached callback function duration is 40ms (the callback function does some processing and displays the image on top of a label). As far I see that are two options for the bahaviour of Qtimer:

    1. The next callback function will be called only after the previous function finished.
    2. The functions will be called in an asynchronous way.

    d3498af1-a03e-4c42-97a3-47dbe0c85292-image.png

    Anybody can clarify what's happening exactly? Does the interval has any meaning in this case?

    Thanks
    Yuval

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If everything is done in the same thread, then it's going to be no 1 as the event loop will be blocked while doing your image processing and thus the timer will fire as soon as possible after that. Therefore, it's no use having a timer that is firing quicker that the processing time of your slot.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      2
      • Y Offline
        Y Offline
        yuvalg1987
        wrote on last edited by
        #3

        Thanks for the quick reply! As processing time varies between different computers is Qtimer the right choice for this application?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Well, it depends on your image source and the goal of your application.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            If everything is done in the same thread, then it's going to be no 1 as the event loop will be blocked while doing your image processing and thus the timer will fire as soon as possible after that. Therefore, it's no use having a timer that is firing quicker that the processing time of your slot.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @SGaist said in Qtimer Behaviour:

            the timer will fire as soon as possible after that.

            I have wondered exactly what the behaviour of a QTimer is when it "misses" timeouts because of being busy. Let's say:

            • Timer times out every 1 second.

            • Blocking code runs for 9.5 seconds.

            I assume that this causes:

            • Timer times out at 9.5 seconds, as soon as it can after blocking code exits.

            • Timer does not issue timeouts for the "missed" 9 timeouts.

            • Timer now starts a brand new 1 second timeout from when it last expired (9.5 seconds), so next times out at 10.5 seconds.

            Are these last 3 indeed the behaviour?

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yuvalg1987
              wrote on last edited by
              #6

              Ok, the timer attached function executes 3 identical functions, each updates a different label (so updating 3 labels in total). Ideally, I can execute all three functions as shown in drawing #2 and cut the execution time of my timer attached function by X3. How can I implement such behaviour? I see slot/signals won't help here.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                There's still one fundamental issue here: your processing time is bigger than your timeout. What's is the point of firing your timer quicker than your processing time ? It's counter productive in the end, either have a pace that allows for proper processing, improve your processing time (not always possible I know) or go for a different architecture.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

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