[Qt-interest] QTimer on Windows in Unreliable for Small (16ms - 30ms) Delays

Josiah Bryan jbryan at productiveconcepts.com
Sat Sep 19 02:28:24 CEST 2009


Thiago Macieira wrote:
> Em Segunda-feira 7. Setembro 2009, às 02.48.17, você escreveu:
>> I'm a bit confused - the description for QTimer says:
>>
>> "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"
>>
>> while you said:
>>> That said, QTimer uses the system timer which is unreliable and
>>> inaccurate. You should use the Windows Multimedia Timers if you
>>> something accurate. In fact, QTimer uses multimedia timers for interval
>>> < 10ms (maybe it's <= 10ms, not sure). You can either use 8ms timer and
>>> process every alternate one or use the Windows MM Timer Api directly.
>> so with Win XP, what is the accuracy of QTimer for periods of greater than
>> 10 msecs - is it 1 millisecond or is it more?  Why doesn't QTimer use the
>> Multimedia Timers for all periods?
> 
> Because QTimer isn't a precise timer. It's not guaranteed to be and it doesn't 
> pretend to be.
> 
> If you need high-precision timers, you'll have to find a way of getting them 
> yourself. QTimer is meant for normal-priority tasks where being a few 
> milliseconds late is ok. Conserving power (reducing the number of CPU wakeups) 
> is more important than precision.
> 

Thiago - thanks for replying. Sorry for getting to this so late.

I have no problem with a few milliseconds - heck, even 100 or 200ms is 
fine once in a while. But averaging 1000ms delays every 5 - 10 seconds - 
thats simply unacceptable. I dont need high-precision, but some 
resemblance of reliability would be nice. A jump from 33ms to 1000ms is 
not just a few milliseconds, thats several orders of magnitude larger.

If theres no way around the 1000ms jump - would you or anyone else at 
trolltech be able to offer any code samples on using Win32 multimedia 
timers in a Qt app? I havn't been able to dig up any examples of win32 
MM timers + Qt since this thread started - and I've been persistent at 
google. I've even tried parsing the Qt source tree for how you folks do 
it - but I can't seem to separate the MM-specific parts from the rest of 
the core. Anything you can offer would be greatly appreciated.

Thanks!
-josiah


-- 
Josiah Bryan
Productive Concepts, Inc.
jbryan at pciint.com
(765) 964-6009, ext. 224




More information about the Qt-interest-old mailing list