[Qt-interest] how do use the timer to calculate the time duration

Ferenc Stelcz ferenc at stelcz.hu
Mon Jun 22 21:06:56 CEST 2009


Yuvaraj R wrote:
> Hi
> 
>  how do i stop the timer...
> 
> once i calculated the time...
> 
> there is no methed to stop the timer
> On Mon, Jun 22, 2009 at 11:29 PM, Ferenc Stelcz <ferenc at stelcz.hu> wrote:
> 
>>  Yuvaraj R wrote:
>>> Hi All
>>>
>>> I want to calculate the  task completion time..
>>>
>>>   So   How do use the timer to calculate the time duration..
>>>
>>>
>>> Thanks
>>>
>>> Yuvaraj R
>>>
>> There are more and more of "your" ermmm.. kind of "developers"... :D
>>
>> Assistant -> Search -> "QTime" -> void QTime::start();
>>
>> from the 2nd line:
>>
>> QTime t;
>> t.start();
>> some_lengthy_task();
>> qDebug("Time elapsed: %d ms", t.elapsed());
>>

Please do NOT reply to me personally! PLEASE reply to the list at the address: 
qt-interest at trolltech.com and NOT qt-interest-subscribe at trolltech.com.

As for your question:

How would you do it in plain C++?

You call t.start() then an ??internal timer?? gets started. (I'm have almost 
never had a look at Qt's internal source, so you'll be at your own from this 
point...) As soon as you call t.elapsed() this timer is stopped and the time 
difference in milliseconds between the start and finish time is returned. You 
don't have to stop it. It's done for you!

so:

QTime t;
t.start();
/*
	do
	your
	job
	here
*/
qDebug("My job took ( %d ) milliseconds to execute.", t.elapsed());

--
Ferenc Stelcz
Junior Software Engineer

Banyan Technologies LLC.


__________ Information from ESET Smart Security, version of virus signature database 4177 (20090622) __________

The message was checked by ESET Smart Security.

http://www.eset.com





More information about the Qt-interest-old mailing list