Results 1 to 17 of 17

Thread: Current Time with microsecond precision on windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    you mean it just gives a millisecond accurate time and the microseconds are a kind of rand() % 999 ?
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

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

    Default Re: Current Time with microsecond precision on windows

    Quote Originally Posted by Dwarf007
    you mean it just gives a millisecond accurate time and the microseconds are a kind of rand() % 999 ?
    Or set to 0. But generaly yes, it might be so.

  3. #3
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Current Time with microsecond precision on windows

    *grumpfl*

    Ok thanks.. I think I will do something like that then.. (rand() % 999)
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

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

    Default Re: Current Time with microsecond precision on windows

    Why do you need microseconds anyway?

  5. #5
    Join Date
    Mar 2006
    Location
    somewhere between France & Germany
    Posts
    34
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up [SOLVED] Current Time with microsecond precision on windows

    wysota: I want to do a kind of portable and accurate gettimeofday();

    Here is the solution, in case someone wants to do the same one day.
    No garantie on it but it seems to work.

    Windows part for a portable gettimeofday():

    Qt Code:
    1. #ifdef _WIN32_
    2.  
    3. #include <windows.h>
    4.  
    5. int gettimeofday( struct timeval *tv, struct timezone *tz )
    6. {
    7. time_t rawtime;
    8.  
    9. time(&rawtime);
    10. tv->tv_sec = (long)rawtime;
    11.  
    12. // here starts the microsecond resolution:
    13.  
    14. LARGE_INTEGER tickPerSecond;
    15. LARGE_INTEGER tick; // a point in time
    16.  
    17. // get the high resolution counter's accuracy
    18. QueryPerformanceFrequency(&tickPerSecond);
    19.  
    20. // what time is it ?
    21. QueryPerformanceCounter(&tick);
    22.  
    23. // and here we get the current microsecond! \o/
    24. tv->tv_usec = (tick.QuadPart % tickPerSecond.QuadPart);
    25.  
    26. return 0;
    27. }
    28. #endif // _WIN32_
    To copy to clipboard, switch view to plain text mode 
    Last edited by Dwarf007; 4th April 2006 at 12:53.
    • The Manual said the program required Win95 or better, so I installed Linux.
    • Newton was a pessimist.
    • no Risk! no FuN!

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Current Time with microsecond precision on windows

    .... and here's a class using those funcs (if it's any help)

    K
    Attached Files Attached Files

Similar Threads

  1. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  2. Replies: 15
    Last Post: 21st April 2007, 17:46

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
  •  
Qt is a trademark of The Qt Company.