Qt World Summit: Register Today!

If the execution time of slot function is greater than the interval of qtimer?

  • slots:
        /* if it will need 1000ms to finish */
        void doBusyThings()
    QTimer* timer = new QTimer(this);
    connect(timer, SIGNAL(tiermOut()), this, SLOT(doBusyThings()));

    What happens to doBusyThings()?

    I mean doBusyThings() will be pushed into a queue and wait to execute? Or kill the running doBusyThings() and continue to execute the next?

  • Moderators

    that depends, do you do sketchy stuff in busyThings, like start a QEventLoop or call ProcessEvents ?

    If not, than the timeout events are queued and executed the next eventloop cycle.

  • Lifetime Qt Champion

    Hi @Limer,

    just to add to @J-Hilk: The events will be queued, but during your long slot no events will be processed.

    That means, if you resize your window in that time, it will not be redrawn (Except you use ProcessEvents or start a local event loop).

    So there are two solutions:

    1. split doBusyThings() into smaller pieces that take much shorter time to execute
    2. use a separate thread to execute the long lasting tasks


  • @aha_1980 @J-Hilk Thanks a lot, i get it!

Log in to reply