Skip to content


QTimer timer;
co_await timer;

The QCoro frameworks allows co_awaiting on QTimer object. The co-awaiting coroutine is suspended, until the timer finishes, that is until QTimer::timeout() signal is emitted.

The timer must be active. If the timer is not active (not started yet or already finished) the co_await expression will return immediately.

To make it work, include qcoro/timer.h in your implementation.

#include <qcoro/timer.h>
#include <chrono>

using namespace std::chrono_literals;

QCoro::Task<> MyClass::pretendWork() {
    // Creates and starts a QTimer that will tick every second
    QTimer timer;

    for (int i = 1; i <= 100; ++i) {
        // Wait for the timer to tick
        co_await timer;
        // Update the progress bar value
        // And repeat...
    // ... until the for loop finishes.