QTimer with value of 0



  • Do I understand correctly that if you set a QTimer with a value of 0 and upon its timeout you run a function, that basically what is happening is that the function will run on the same thread that called the timer, usually GUI, but that it will essentially not run the function until any UI events have been processed first, is that correct?

    This strategy pops up occasionally when reading about threads, but as far as I can tell, it is not actually processing anything on another thread, right?


  • Moderators

    [quote author="qttester5" date="1397472767"]Do I understand correctly that if you set a QTimer with a value of 0 and upon its timeout you run a function, that basically what is happening is that the function will run on the same thread that called the timer[/quote]No. It depends on 2 things:

    This is the same for all signal-slot connections.

    [quote]it will essentially not run the function until any UI events have been processed first, is that correct?[/quote]If there are no events to process in the slot thread, the function will run immediately when the timer times out.

    If the slot thread is in the middle of processing events when the timer times out, the thread will finish processing all pending events and then run the function.

    [quote]This strategy pops up occasionally when reading about threads[/quote]I wouldn't do this. If your timer is repetitive, your thread will try to run the function repeatedly as fast as possible -- your CPU core will be maxed out.


Log in to reply
 

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