Important: Please read the Qt Code of Conduct -

Qtimer Behaviour

  • 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.


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


  • Lifetime Qt Champion


    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.

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

  • Lifetime Qt Champion

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

  • @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?

  • 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.

Log in to reply