Qt-interest Archive, March 2007
Accurate timer.
Message 1 in thread
Guys,
I need a top accurate timer,
since it's based on a callback I get inconsistant result with the QTimer.
Is there a more "evolved" timer in the Qt library I might use ?
Thanks.
Mr Arnaud.
--
[ signature omitted ]
Message 2 in thread
> -----Original Message-----
> From: qt-interest-request@xxxxxxxxxxxxx
> [mailto:qt-interest-request@xxxxxxxxxxxxx]On Behalf Of bunjeee
> Sent: 13 March 2007 13:17
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Accurate timer.
>
>
> Guys,
>
> I need a top accurate timer,
> since it's based on a callback I get inconsistant result with the QTimer.
>
> Is there a more "evolved" timer in the Qt library I might use ?
>
No
> Thanks.
>
> Mr Arnaud.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 3 in thread
Hi,
> I need a top accurate timer,
> since it's based on a callback I get inconsistant result with the QTimer.
What do you mean by inconsistent? What exactly do you expect (in an
event-based environment)?
> Is there a more "evolved" timer in the Qt library I might use ?
Maybe we can find something if you describe your needs in more detail.
Do you just need a time stamp?
Or do you need to trigger some action with a precision better than the
event loop can handle? If so what are you trying to achieve? Is it
related to video?
--
[ signature omitted ]
Message 4 in thread
Hey,
Well I'm moving 2d shapes in a scene.
I need to have the same speed on any machine.
Provided the fact QTimer uses a callback you won't get the same ticks
depending on the CPU.
So I need a timer based on time for me to determine where the item has moved
since the last time.
Thanks.
Mr Arnaud.
----- Original Message -----
From: "Dimitri" <dimitri@xxxxxxxxxxxxx>
To: <qt-interest@xxxxxxxxxxxxx>
Sent: Tuesday, March 13, 2007 9:40 PM
Subject: Re: Accurate timer.
> Hi,
>
>> I need a top accurate timer,
>> since it's based on a callback I get inconsistant result with the QTimer.
>
> What do you mean by inconsistent? What exactly do you expect (in an
> event-based environment)?
>
>> Is there a more "evolved" timer in the Qt library I might use ?
>
> Maybe we can find something if you describe your needs in more detail.
>
> Do you just need a time stamp?
>
> Or do you need to trigger some action with a precision better than the
> event loop can handle? If so what are you trying to achieve? Is it related
> to video?
>
> --
> Dimitri
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 5 in thread
Hi,
> Well I'm moving 2d shapes in a scene.
> I need to have the same speed on any machine.
You should be able to do that with the timers provided with Qt. What
exact problem do you have with using such timers?
--
[ signature omitted ]
Message 6 in thread
Let me give you an example,
I'm using a very small timing value..
Tick... Let's say Qt calls its timer's callback,
During that process the timer ticks once more (or should be) but the program
is still executing the previous callback operations.
What should be used to prevent that king of issue is the following process :
- If timer occurences since last callback > 1.
- Then move the shape from 2 blocks instead of one.
You could call that frameskip, just like what console and nes/snes emulators
uses.
I'm searching that kind of timer in the Qt standard library or something
portable,
thus avoiding me using the Win32 advanced timer.
Thanks.
Mr Arnaud.
----- Original Message -----
From: "Dimitri" <dimitri@xxxxxxxxxxxxx>
To: <qt-interest@xxxxxxxxxxxxx>
Sent: Tuesday, March 13, 2007 9:49 PM
Subject: Re: Accurate timer.
> Hi,
>
>> Well I'm moving 2d shapes in a scene.
>> I need to have the same speed on any machine.
>
> You should be able to do that with the timers provided with Qt. What exact
> problem do you have with using such timers?
>
> --
> Dimitri
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 7 in thread
bunjeee wrote:
> Let me give you an example,
>
> I'm using a very small timing value..
>
> Tick... Let's say Qt calls its timer's callback,
> During that process the timer ticks once more (or should be) but the
> program is still executing the previous callback operations.
>
> What should be used to prevent that king of issue is the following
> process :
> - If timer occurences since last callback > 1.
> - Then move the shape from 2 blocks instead of one.
>
> You could call that frameskip, just like what console and nes/snes
> emulators uses.
>
> I'm searching that kind of timer in the Qt standard library or
> something portable,
> thus avoiding me using the Win32 advanced timer.
>
>
>
>
Why base your movement off "ticks"? If the movement is time related
then have your slot (sort of callback) use something like
QTime::elapsed() to move in pixels/ms. You will still need to use the
eventloop to physically paint anyway so frame dropping will be necessary
if your single threaded process is calc heavy.
--Justin
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard
Message 8 in thread
Justin Noel wrote:
> bunjeee wrote:
>> ...
>> You could call that frameskip, just like what console and nes/snes
>> emulators uses.
>> ...
> Why base your movement off "ticks"? If the movement is time related
> then have your slot (sort of callback) use something like
> QTime::elapsed() to move in pixels/ms. You will still need to use the
I fully agree with Justin: if what you want is merely a "frame-skip"
approach all you need to know is the elapsed time between the current
paint event and the last one - and this value you get with
QTime::elapsed(), or in this case with restart() which returns the same
value as elapsed(), but immediatelly restarts the timer for the next
paint event. Millisecond precision should be fully sufficient, since the
human eye is probably much more forgiving than you think ;)
void MyWidget::paintEvent (...)
{
// time since the last paint event
time dt = m_time.restart();
// scale somehow the distance the object moves
double dx = m_myObject.velocityX() * dt;
double dy = m_myObject.velocityY() * dt;
// move the object, scaled with the elapsed time
m_myObject.move (dx, dy);
// paint the object(s)
...
}
Off course the above formula needs some refinment, but you get the idea
how to use restart().
But are you actually implementing some video playback/decoder? Your
description sounds like ("move objects 2 blocks instead of one"). But
anyway, QTimer::restart() could help you there, too.
But if you *really* need some high-precision hardware timer, someone
posted assembler (!) code on this list a loooong time ago (4 years+)
which off course was processor dependent (i386 architekture). I think it
had something to do with measuring OpenGL framerates, so you might be
lucky when googling with "OpenGL FPS timer" or similar (or try the Qt
interest archive).
Cheers, Oliver
--
[ signature omitted ]
Message 9 in thread
On Wednesday 14 March 2007 10:08, Till Oliver Knoll wrote:
> Justin Noel wrote:
> > bunjeee wrote:
> >> ...
> >> You could call that frameskip, just like what console and nes/snes
> >> emulators uses.
> >> ...
> >
> > Why base your movement off "ticks"? If the movement is time related
> > then have your slot (sort of callback) use something like
> > QTime::elapsed() to move in pixels/ms. You will still need to use the
>
> I fully agree with Justin: if what you want is merely a "frame-skip"
> approach all you need to know is the elapsed time between the current
> paint event and the last one - and this value you get with
> QTime::elapsed(), or in this case with restart() which returns the same
> value as elapsed(), but immediatelly restarts the timer for the next
> paint event. Millisecond precision should be fully sufficient, since the
> human eye is probably much more forgiving than you think ;)
Just an FYI: the QTimeLine class takes care of all of this for you, see
http://doc.trolltech.com/4.2/qtimeline.html
--
[ signature omitted ]
Message 10 in thread
Thank you all,
I'm using QTime coupled with a QTimer.
It's working like a charm.
Mr Arnaud.
----- Original Message -----
From: "Bradley T Hughes" <bhughes@xxxxxxxxxxxxx>
To: <qt-interest@xxxxxxxxxxxxx>
Sent: Wednesday, March 14, 2007 10:58 AM
Subject: Re: Accurate timer.
> On Wednesday 14 March 2007 10:08, Till Oliver Knoll wrote:
>> Justin Noel wrote:
>> > bunjeee wrote:
>> >> ...
>> >> You could call that frameskip, just like what console and nes/snes
>> >> emulators uses.
>> >> ...
>> >
>> > Why base your movement off "ticks"? If the movement is time related
>> > then have your slot (sort of callback) use something like
>> > QTime::elapsed() to move in pixels/ms. You will still need to use the
>>
>> I fully agree with Justin: if what you want is merely a "frame-skip"
>> approach all you need to know is the elapsed time between the current
>> paint event and the last one - and this value you get with
>> QTime::elapsed(), or in this case with restart() which returns the same
>> value as elapsed(), but immediatelly restarts the timer for the next
>> paint event. Millisecond precision should be fully sufficient, since the
>> human eye is probably much more forgiving than you think ;)
>
> Just an FYI: the QTimeLine class takes care of all of this for you, see
> http://doc.trolltech.com/4.2/qtimeline.html
>
> --
> Bradley T. Hughes - bhughes at trolltech.com
> Trolltech ASA - Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]