PDA

View Full Version : Problem with QTimer under Win XP



wzielj
25th January 2009, 00:22
I use QTimer to schedule events every 20ms. Unfortunately under Win XP scheduling doesn't work.



timer = new QTimer(this);
//Co 1/50s event
timer->start(20);
QObject::connect( timer, SIGNAL( timeout() ), this,SLOT( timerEvent() ) );

I think timer not always send signal - i mean if i put line mesurement += 0.02 in timerEvent method than after 10 sec mesurement is 8.6..

I've tried with qt_win_use_simple_timers=true; but i received compilation's error. If this solution might work please explain me step by step how to fix it...I use QT v 4.4.3

seneca
25th January 2009, 01:02
From the docs:


Note that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 1 millisecond, but Windows 98 supports only 55. If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.

Could this be the case?

wzielj
25th January 2009, 01:07
Propably yes but is there any other way i can call ops every 20ms ?

seneca
25th January 2009, 08:17
I think the problem is that sometimes the slot is running 20 ms or longer. This is a basic problem that you can only to a certain extent solve by optimizing, but you can never solve it completely because XP is not a realtime operating system where you have guarantee about the processing time assigned to a certain thread or process.

Maybe you should explain more what your goal is, there could be a better approach than timers, unless you really need realtime capability.

wzielj
25th January 2009, 09:49
My aim is to call an event exactly every 20ms

wysota
25th January 2009, 11:18
My aim is to call an event exactly every 20ms

Just for fun or is there anything more into it? :)

Lesiok
25th January 2009, 14:00
Event recurrence in time is warranted only in RTOS. Windows XP is not RTOS.

The Storm
25th January 2009, 15:53
You can try with events, because they are 10 function calls faster than the signals/slots, perhaps you will get better results. For more info - http://doc.trolltech.com/4.4/qobject.html#timerEvent

wysota
25th January 2009, 17:59
Timers (regardless of how you use them) do not guarantee they will called exactly every interval miliseconds. If you set a timeout to 100ms, it can be called from 0 to 10 times within a second and there is nothing you can do about it, it's just the way timers work on non-realtime operating systems.

faldzip
26th January 2009, 14:04
and if you really want that event every 20ms you have to use some real time operating system, like QNX.