Search code examples
qtqt5qtimer

QTimer: can timer-callback be executed overlapping?


Assumed I have a QTimer which is set up to call its timer-function every 40 msec. Furthermore assumed, the timer-function called by that function needs 200 msec until it returns. So what happens to my timer now (ignoring any jitter and timer-inaccuracies for this example):

  • is the timer-function called every 40 msecs so that after some time I have 5 overlapping calls of threads being in the same function at the same time?
  • is the timer called every 200 msec?
  • is the timer called every 240 msec?

Thank you!


Solution

  • I've simulated your case by a piece of code and result was the third, timer called every 240 ms.

    This is the output of my code:

    timer callback  1  time  QTime("09:44:01.396")
    timer callback output  1  time  QTime("09:44:01.633")
    timer callback  2  time  QTime("09:44:01.640")
    timer callback output  2  time  QTime("09:44:01.875")
    timer callback  3  time  QTime("09:44:01.875")
    timer callback output  3  time  QTime("09:44:02.116")
    timer callback  4  time  QTime("09:44:02.116")
    timer callback output  4  time  QTime("09:44:02.354")
    timer callback  5  time  QTime("09:44:02.354")
    timer callback output  5  time  QTime("09:44:02.585")
    

    P.S:

    timer callback 1 time QTime("09:44:01.396")

    This line appear when timer timeouts

    timer callback output 1 time QTime("09:44:01.633")

    And this when the callback function completely done.