PDA

View Full Version : <time.h>



mickey
28th February 2006, 16:11
Hi,
I need to do a countdown of a time (i.e. 3':40''). I must to code myself (3':00''...2':59''....)it or are there any istructions simplify my life?
Thanks?

jpn
28th February 2006, 16:32
Is there a need for using time.h? Why not use timer events offered by Qt?
See QObject::startTimer(int interval) (http://doc.trolltech.com/3.3/qobject.html#startTimer)

mickey
28th February 2006, 19:09
I Need not use QT for this.........any suggest?

wysota
28th February 2006, 19:29
There are surely system timers which you can use. For example under Linux you can use setitimer(). I'm sure Windows has something simmilar. If not, you can always spawn a separate thread and put it to sleep() for the desired amount of time and after it wakes up, it can somehow signal the main thread that the time has passed.

brcain
1st March 2006, 15:32
clock_t ticks; // Time in clock ticks

// If Windows ...
ticks = clock();

// else ...
struct tms tmpBuffer;
ticks = times(&tmpBuffer);

dublet
3rd March 2006, 10:20
Depends on the accuracy you need, but UN*X times provide easy calculation. Use the time() function to get the current time. Then convert the supplied time to seconds since January 1st 1970. Subtract the two, and you have your countdown in seconds. Converting to minutes and hours should be trivial.

mickey
3rd March 2006, 11:44
I don't need take current time. i need to have a variable that I set 'a time' (eg 4':30''). Then begin countdown of this.....I'm in widows....

jacek
3rd March 2006, 13:02
I don't need take current time. i need to have a variable that I set 'a time' (eg 4':30''). Then begin countdown of this.....I'm in widows....
Convert it to seconds and store them as integer. If you don't want to use QTime, you can write your own class --- it should take only a couple of minutes to implement it.