Results 1 to 6 of 6

Thread: Accurate time mesurement in Qt. (QueryPerformanceCounter equivalent?)

  1. #1

    Default Accurate time mesurement in Qt. (QueryPerformanceCounter equivalent?)

    Hi all,

    I need to mesure time from one moment to another.
    Is there are any equivalent of WinAPI QueryPerformanceCounter()?

    Needed accuracy is at least 20 ms. I could use QTime::start() and QTime::ellapsed() but this approach gives problems if someone change system time.

    Probably I could use some function that returns time from the begining of runing the application. Wich would be good thing. But I cant find any function like this.

    So I need robust and accurate time mesurement. Any ideas?

    Thanks
    Last edited by progDes; 14th May 2009 at 07:44.

  2. #2
    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: Accurate time mesurement in Qt. (QueryPerformanceCounter equivalent?)

    You can have a QTimer that timeouts every 20ms and keeps track of the time itself but I'd say this is a bit too much of an effort. Why can't you use the native API function? Also you can take Qt's sources and see how Q_BENCHMARK macro is implemented - you can even borrow its code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: Accurate time mesurement in Qt. (QueryPerformanceCounter equivalent?)

    Quote Originally Posted by wysota View Post
    You can have a QTimer that timeouts every 20ms and keeps track of the time itself but I'd say this is a bit too much of an effort. Why can't you use the native API function? Also you can take Qt's sources and see how Q_BENCHMARK macro is implemented - you can even borrow its code.
    The problems that there is no garantee that timer function will be called exactly every 20 ms. Some time will be lost on message-loop. And the main problem - system stress, when timer can return even in few seconds instead of 20 ms.

    I can use platform specific API's but wanted to have one code for all platforms. Althought looks like it's not possible.

  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: Accurate time mesurement in Qt. (QueryPerformanceCounter equivalent?)

    If you're not using a real-time OS then you will never have any guarantees.

    And it doesn't matter if the timer fires after 20ms or 21ms, you have a QTime object to measure the time difference between timeouts. It won't be possible to use the same code for all platforms because each system has its own policy when it comes to timers (including different timer resolutions), so if you need something really precise, you'll have to dig into native API (although again without a RTOS it doesn't make much sense).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: Accurate time mesurement in Qt. (QueryPerformanceCounter equivalent?)

    I've decided to use QueryPerformanceCounter in Windows. And mach_absolute_time oon MacOs. Both functions are actualy doing the same and can mesure time very precise.

  6. #6
    Join Date
    Mar 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accurate time mesurement in Qt. (QueryPerformanceCounter equivalent?)

    Maybe it's too late to reply, but I was looking for a substitute for QueryPerformanceCounter in Qt and found "QElapsedTimer" class new-added in Qt 4.7.

    This class has it all

Similar Threads

  1. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 16:39

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.