PDA

View Full Version : QTimer stops after system time change



djurodrljaca
30th April 2009, 11:58
I am making an application on embedded linux (ARM - PXA255) with Qt for Embedded Linux 4.5.1 and I have a problem with QTimer when I change system time (another process or command line).

When I change the system time forward the timer triggers timeout() signal immediately, but when I change the system time backward the timer never (or maybe it just takes too long) triggers timeout() signal.

What I want is for timer to trigger timeout() signal on the desired interval in "real" time.

I am working with intervals of 1 second or grater.

Is there a simple solution to this, or should I just create a new timer class that uses "native" linux functions and just sent the timeout() signal from this new timer class?

e8johan
30th April 2009, 12:25
Using the native function is "dangerous", as you can mess up the Qt threading and timer system by introducing other sources of timer events.

Have you tried experimented with QObject's startTimer, stopTimer and timerEvent? Perhaps you can make that work.

djurodrljaca
30th April 2009, 13:11
Using the native function is "dangerous", as you can mess up the Qt threading and timer system by introducing other sources of timer events.

Have you tried experimented with QObject's startTimer, stopTimer and timerEvent? Perhaps you can make that work.

Tried it, but it still wont work, probably because QTimer user these functions.

I tried one simple "native" timer and it worked for smaller changes in time, but when this time difference is big the "native" timer also fails.

djurodrljaca
1st May 2009, 21:36
So I fixed my problem.

First I had to use newer glibc (2.3.2 -> 2.3.3), then I had to find out if my embedded system can use monotonic timers (I wrote a simple timer class that acted like QTimer, but it used clock_nanosleep and clock_gettime for sleep).

The I had to find out what is the problem with Qt, and it appears that Qt doesn't detect monotonic timers on my embedded system.
So I changed the variable "useMonotonicTimers" to "true" in qeventdispatcher_unix.cpp (line 266) and recompiled Qt. Now it works correctly.