Results 1 to 7 of 7

Thread: Problem wit QTimer, different time, why?

  1. #1
    Join Date
    Apr 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Problem wit QTimer, different time, why?

    Hello!!
    I am implementing one video reproducer and the refresh is 40 ms.
    To make this i use one timer:

    Qt Code:
    1. timer = new QTimer();
    2. connect(timer, SIGNAL(timeout()), this, SLOT(updateLabel()));
    3. timer->start(40);
    4.  
    5. updateLabel()
    6. {
    7. XXXXXXXXXX
    8. Label->setPixmap(QPixmap::fromImage(qimg_l));
    9. }
    To copy to clipboard, switch view to plain text mode 

    But when i load the video the first time is slower than the second, third, ...
    I use for example one refresh of 1s and the video is loaded too the first time at 1s for each frame, but the second, third, faster than the first.
    Why this thing? Any idea?

    Thank you
    Last edited by jpn; 6th August 2008 at 12:10. Reason: missing [code] tags

  2. #2
    Join Date
    Apr 2008
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Problem wit QTimer, different time, why?

    No idea? Can you help me?
    Thanks!

  3. #3
    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: Problem wit QTimer, different time, why?

    The timer will not be fired every 40ms, but not earlier than 40ms after the last timeout.

  4. #4
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Thanks
    3
    Thanked 12 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Problem wit QTimer, different time, why?

    Quote Originally Posted by wysota View Post
    The timer will not be fired every 40ms, but not earlier than 40ms after the last timeout.
    Even though the QTimer docs says they are 1 ms accurate, that's partially true, because QTimers are depending on other tasks in your application. For fun you can add a few 1000 qtimers, and plot the time for each of them to see what wysota is talking about. (Or find something that maxes your cpu usage while using qtimers in another program...)

    You can use QDateTime and get the milliseconds timer to do a better timing. for instance if you need 40ms timing, set the timer to something faster than 40 ms and use the milliseconds from qdatetime to trigger en event at exactly 40ms from last time. (just save your last-time somewhere...) Although this is not a particullary good solution..

    I suggest reading this article covering the subject with some data and tests:
    The Qt Framework and (soft) real-time projects

    Short summary is in win32, use win32 native periodic timer, on linux, use RTC wait.

    you also might want to run your timing in a seperate thread/process...

    cheers,
    leif

  5. #5
    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: Problem wit QTimer, different time, why?

    Quote Originally Posted by luf View Post
    Even though the QTimer docs says they are 1 ms accurate, that's partially true,
    They are not 1ms accurate, they have a resolution of 1ms and that's two different things.

  6. #6
    Join Date
    Apr 2006
    Location
    Denmark / Norway
    Posts
    67
    Thanks
    3
    Thanked 12 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Problem wit QTimer, different time, why?

    Quote Originally Posted by wysota View Post
    They are not 1ms accurate, they have a resolution of 1ms and that's two different things.
    Thanks for correcting! Of course it's resolution... as if they were 1 ms accurate, the problem wouldn't be there!

    On the other hand, I read from the docs that the "accuracy depends on the underlying platform", and "Most platforms support an accuracy of 1 millisecond". That was made me think accuracy, while it's really resolution it should say.

    thanks,
    leif

  7. #7
    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: Problem wit QTimer, different time, why?

    You can report a bug in the docs then It should definitely say "resolution" there.

Similar Threads

  1. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 16:50
  2. QTimer problem
    By vv in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2007, 08:13
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. Replies: 6
    Last Post: 17th March 2006, 17:48
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48

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.