Results 1 to 10 of 10

Thread: Problem with QTimer under Win XP

  1. #1

    Default Problem with QTimer under Win XP

    I use QTimer to schedule events every 20ms. Unfortunately under Win XP scheduling doesn't work.

    Qt Code:
    1. timer = new QTimer(this);
    2. //Co 1/50s event
    3. timer->start(20);
    4. QObject::connect( timer, SIGNAL( timeout() ), this,SLOT( timerEvent() ) );
    To copy to clipboard, switch view to plain text mode 
    I think timer not always send signal - i mean if i put line mesurement += 0.02 in timerEvent method than after 10 sec mesurement is 8.6..

    I've tried with qt_win_use_simple_timers=true; but i received compilation's error. If this solution might work please explain me step by step how to fix it...I use QT v 4.4.3

  2. #2
    Join Date
    Jan 2006
    Posts
    132
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 16 Times in 16 Posts

    Default Re: Problem with QTimer under Win XP

    From the docs:

    Note that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 1 millisecond, but Windows 98 supports only 55. If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.
    Could this be the case?

  3. #3

    Default Re: Problem with QTimer under Win XP

    Propably yes but is there any other way i can call ops every 20ms ?

  4. #4
    Join Date
    Jan 2006
    Posts
    132
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 16 Times in 16 Posts

    Default Re: Problem with QTimer under Win XP

    I think the problem is that sometimes the slot is running 20 ms or longer. This is a basic problem that you can only to a certain extent solve by optimizing, but you can never solve it completely because XP is not a realtime operating system where you have guarantee about the processing time assigned to a certain thread or process.

    Maybe you should explain more what your goal is, there could be a better approach than timers, unless you really need realtime capability.

  5. #5

    Default Re: Problem with QTimer under Win XP

    My aim is to call an event exactly every 20ms

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    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: Problem with QTimer under Win XP

    Quote Originally Posted by wzielj View Post
    My aim is to call an event exactly every 20ms
    Just for fun or is there anything more into it?

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: Problem with QTimer under Win XP

    Event recurrence in time is warranted only in RTOS. Windows XP is not RTOS.

  8. #8
    Join Date
    Aug 2007
    Posts
    166
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    16
    Thanked 14 Times in 14 Posts

    Default Re: Problem with QTimer under Win XP

    You can try with events, because they are 10 function calls faster than the signals/slots, perhaps you will get better results. For more info - http://doc.trolltech.com/4.4/qobject.html#timerEvent

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    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: Problem with QTimer under Win XP

    Timers (regardless of how you use them) do not guarantee they will called exactly every interval miliseconds. If you set a timeout to 100ms, it can be called from 0 to 10 times within a second and there is nothing you can do about it, it's just the way timers work on non-realtime operating systems.

  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 140 Times in 132 Posts

    Default Re: Problem with QTimer under Win XP

    and if you really want that event every 20ms you have to use some real time operating system, like QNX.

Similar Threads

  1. Problem with operating of QTimer
    By sudheer168 in forum Newbie
    Replies: 3
    Last Post: 8th October 2008, 21:58
  2. QTimer problem
    By rajeshs in forum Qt Programming
    Replies: 3
    Last Post: 13th September 2008, 15:33
  3. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 13:48
  4. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 17:50
  5. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54

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.