Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QWS and QTimer resolution
Forum Updated to NodeBB v4.3 + New Features

QWS and QTimer resolution

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 4 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    denizlitr
    wrote on last edited by
    #1

    Hi all,

    I have 2 widgets, both have the size 300x300 pixels. Each widgets have their own QTimer set periodically to fire every 20ms. In the timeout() slots, I make some small calculations and call update(). In the method paintEvent() I paint a QPixmap.

    The timer of the second object is started 1 second after the first objects timer is started.

    Here is the pseudo code of timeout slot and paint event:
    @
    void timeout()
    {
    print_time();
    do_some_calc();
    update();
    }
    void paintEvent(.....)
    {
    print_time();
    QPainter painter(this);
    painter.drawPixmap(0,0,myPixmap);
    print_time();
    }
    @

    When I start the first timer, the timer slot is called about every ~40ms. When even the object starts its timer, the timers get fired about every ~80 ms.
    The paintEvent consumes about 5-7 ms.
    When I comment out the update() calls in the timeout slots, the timers get fired about 21-22 ms.

    My question is, why I get such a bad resolution and any advice to workaround this?

    My system runs under PPC, Linux 3.1.4 and Qt 4.7.4. The behaviour is under both framebuffer und DirectFB the same.

    [edit, @ code tags added, Eddy]

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

      According to the QObject::Timer documentation (QTimer is just a higher-level wrapper around the basic QObject functionality):

      "Note that QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some."

      So you are really pushing the system's limit asking for 20ms repeats. There is a lot of overhead in a GUI program related to various windowing events in the event queue, and not only does a timer depend on the system's clock, it also depends on the contents of the event queue.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        Apart from the underlying timer support -- which depends on your exact combination of hardware and software, although I think you should be able to get 1ms resolutions -- you can't really ask for a 20ms timer and then spend more than 20ms for drawing and/or doing calculations...

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          [quote author="denizlitr" date="1324049553"]
          @
          void timeout()
          {
          print_time();
          do_some_calc();
          update();
          }
          void paintEvent(.....)
          {
          print_time();
          QPainter painter(this);
          painter.drawPixmap(0,0,myPixmap);
          print_time();
          }
          @

          When I start the first timer, the timer slot is called about every ~40ms. When even the object starts its timer, the timers get fired about every ~80 ms.
          The paintEvent consumes about 5-7 ms.
          When I comment out the update() calls in the timeout slots, the timers get fired about 21-22 ms.
          [/quote]

          you are only tracing times for your methods. but update does not directly lead to paintEvent. Update triggeres an upodate event which will be processed by the event loop the next round. There some other classes do some magic (like raster operations,. clipping, double buffering, ...).

          If you want to measure the full time for an update, you would have to trace the times some where else, deep inside Qt.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved