Qt Basic Usage


Example

QTimer add the functionality to have a specific function/slot called after a certain interval (repeatedly or just once).

The QTimer thus allows a GUI application to "check" things regularly or handle timeouts without having to manually start an extra thread for this and be careful about race conditions, because the timer will be handled in the main-event loop.

A timer can simply be used like this:

QTimer* timer = new QTimer(parent); //create timer with optional parent object
connect(timer,&QTimer::timeout,[this](){ checkProgress(); }); //some function to check something
timer->start(1000); //start with a 1s interval

The timer triggers the timeout signal when the time is over and this will be called in the main-event loop.