Results 1 to 8 of 8

Thread: <time.h>

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default <time.h>

    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?
    Regards

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: <time.h>

    Is there a need for using time.h? Why not use timer events offered by Qt?
    See QObject::startTimer(int interval)

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: <time.h>

    I Need not use QT for this.........any suggest?
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: <time.h>

    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.

  5. #5
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: <time.h>

    clock_t ticks; // Time in clock ticks

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

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

  6. #6
    Join Date
    Mar 2006
    Posts
    22
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: <time.h>

    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.

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: <time.h>

    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....
    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: <time.h>

    Quote Originally Posted by mickey
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.