timerEvent response overtime
-
I override a timerEvent and set its interval to 10 ms. Then I build the same code both in Windows 10 and Ubuntu 22.04. During run time, the Win version sometimes responsed between two timer slices over 50 ms, even 1 or 2 seconds. But the Ubuntu version run normly. Does it need more configuration in Windows' enviroment?
-
I override a timerEvent and set its interval to 10 ms. Then I build the same code both in Windows 10 and Ubuntu 22.04. During run time, the Win version sometimes responsed between two timer slices over 50 ms, even 1 or 2 seconds. But the Ubuntu version run normly. Does it need more configuration in Windows' enviroment?
@wang1209 said in timerEvent response overtime:
Does it need more configuration in Windows' enviroment?
No, nothing you can do except you switch to a real-time OS.
-
I override a timerEvent and set its interval to 10 ms. Then I build the same code both in Windows 10 and Ubuntu 22.04. During run time, the Win version sometimes responsed between two timer slices over 50 ms, even 1 or 2 seconds. But the Ubuntu version run normly. Does it need more configuration in Windows' enviroment?
@wang1209
I don't use Windows but did you read through enum Qt::TimerType and tryQt::PreciseTimer
? Or there is QChronoTimer, though I think that is overkill for 10ms. -
@wang1209
I don't use Windows but did you read through enum Qt::TimerType and tryQt::PreciseTimer
? Or there is QChronoTimer, though I think that is overkill for 10ms. -
@JonB Yes, I set the second parameter as Qt::PreciseTimer when I call startTimer() like
timerID=startTimer(10, Qt::PreciseTimer);
@wang1209
Well all I know is that the link saysOn Windows, Qt will use Windows's Multimedia timer facility (if available) for Qt::PreciseTimer and normal Windows timers for Qt::CoarseTimer and Qt::VeryCoarseTimer.
Maybe Multimedia timer is not available to you or it's still not accurate, I don't know. For the sake of completeness did you check
QChronoTimer
? You could also test Windows nativeWM_TIMER
or other to see if it's any more accurate than from Qt. If you can't find anything more accurate in Windows then as @Christian-Ehrlicher says maybe you'll never get it out of non-real-time Windows. -
@JonB Yes, I set the second parameter as Qt::PreciseTimer when I call startTimer() like
timerID=startTimer(10, Qt::PreciseTimer);
You can't rely on Windows timer precision in exact milliseconds.
Don't know how Qt's "precise" timer is implemented and what it does to the OS (i.e. Windows)...
as @JonB and @Christian-Ehrlicher say above, for very time sensitive tasks, an RTOS such as QNX or ROS is more suited... but all depends on your use case. -
J JonB referenced this topic on
-
J JonB referenced this topic on