QWS and QTimer resolution



  • 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]



  • 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.



  • 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...



  • [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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.