Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Longtime stability of QTimer events
Certainly QTimer and its events are dependent on CPU clock stability, but that is not the topic here.
I am firing an event every 5 seconds with QTimer. The application runs basically 24/7 and may never stop. I have seen that the timer events are pretty close to 5 seconds and due to other activities there some sort of compensating intervals.
Has anybody experience about stability of the average trigger time? E.g. when the timer is started 2 seconds after full minute, are the 2 seconds (delay) remain over days? Or do I have to maintain this myself?
Again stability with respect to CPU clock is sufficient.
A Former User last edited by A Former User
I think I've found the relevant parts of the code in http://code.qt.io/cgit/qt/qt.git/tree/src/corelib/kernel/qeventdispatcher_unix.cpp. Looking at
QTimerInfoList::activateTimers()it seems that the implementation tries to keep the length of the intervals between two timer events constant and thus does not compensate any drift. (see lines 606..609).
Thanks for valuable information. Unfortunately, I am on windows.
I have opened the _win version but that seems to be diferent.
You are right it looks like the unix version is trying to maintain a constant interval.
However, this does not fit what I experienced a couple of times on windows. As noted above, the timer shall be fired every 5 seconds. I am checking by output of screen the interval between event by differencing the clock readings. Most of the time calculated difference is 5.008 or around that. There are very often values of 4.99?, which might be compensating or have their origin in rounding issues.
However, I have definitely seen also differences of around half of the interval 2.x seconds and the next epoch compensating completely. Not sure, it could be the other way around that a longer interval was always first and the next shorter to compensate.
A Former User last edited by
Look at this: http://code.qt.io/cgit/qt/qt.git/tree/src/corelib/kernel/qeventdispatcher_win.cpp, lines 605 to 628. The implementation on Windows relies solely on the windows API:
timeSetEvent. Maybe you can find out what these functions do in the various Windows versions.
Thanks for the lead, I will do some more investigations then.