Results 1 to 3 of 3

Thread: Qtimer, basictimer bad precision ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    56
    Thanked 1 Time in 1 Post

    Default Qtimer, basictimer bad precision ?

    I have measure the Qtimer, basictimer precision with diferent intervales
    ( I use the simplest code :

    basictimer.start(50, this);
    void AnalogClock::timerEvent(QTimerEvent *event)
    {
    qDebug()<<QTime::currentTime().second()<<"."<<QTim e::currentTime().msec();
    }


    For a 50 msecs I have :
    0 . 0
    0 . 62
    0 . 125
    0 . 187
    0 . 250
    0 . 312
    0 . 375
    0 . 437
    0 . 500
    0 . 562

    For a 200 msecs I have :

    30 . 78
    30 . 281
    30 . 484
    30 . 687
    30 . 890
    31 . 93
    31 . 296
    31 . 500
    31 . 703
    31 . 906
    32 . 109

    I suposse my computer is 'normal'.
    How can I improve my precision ?

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

    Default Re: Qtimer, basictimer bad precision ?

    Quote Originally Posted by tonnot View Post
    I suposse my computer is 'normal'.
    How can I improve my precision ?
    Get a real-time operating system.

    Timers don't guarantee the exact interval specified. They can only guarantee that you will be notified not before the interval passes. The operating system will try to get you as close to this interval as it can but on a "normal" OS it will practically never be exactly the interval you want. The smaller intervals you choose the more accurate timers Qt will use but it all depends on what the operating system has to offer. Currently the devs are working on a new class of timers (I don't know if they made it into 4.7) which will allow higher inaccuracy of a single timer in favour of increasing performance of the whole application by synchronizing timers to fire in the same moment (which will make your application be woken up not so often reducing power and cpu consumption).
    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
    Join Date
    Apr 2010
    Posts
    769
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 94 Times in 86 Posts

    Default Re: Qtimer, basictimer bad precision ?

    Note, also, that you are making to separate calls to currentTime() in your output statement. This is guaranteed to fail whenever the millisecond value "wraps around" during I/O. You should make a single call, store the result, then format it before printing.

Similar Threads

  1. Qwt Scale Label Precision
    By JohnKustrin in forum Qwt
    Replies: 1
    Last Post: 20th August 2010, 19:06
  2. QThread msleep precision
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2007, 00:40
  3. very simple precision question
    By vonCZ in forum General Programming
    Replies: 6
    Last Post: 28th June 2007, 12:46
  4. double precision or what?
    By mickey in forum General Programming
    Replies: 7
    Last Post: 20th February 2007, 21:01
  5. precision problem - Help pls
    By munna in forum General Programming
    Replies: 7
    Last Post: 26th May 2006, 05:00

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.