1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
// SPDX-FileCopyrightText: 2021 Daniel Vrátil <dvratil@kde.org>
//
// SPDX-License-Identifier: MIT
#include "qcorotask.h"
#include "qcorotimer.h"
#include <QCoreApplication>
#include <QDateTime>
#include <QTimer>
#include <chrono>
#include <iostream>
using namespace std::chrono_literals;
QCoro::Task<> runMainTimer() {
std::cout << "runMainTimer started" << std::endl;
QTimer timer;
timer.setInterval(2s);
timer.start();
std::cout << "Waiting for main timer..." << std::endl;
co_await timer;
std::cout << "Main timer ticked!" << std::endl;
qApp->quit();
}
int main(int argc, char **argv) {
QCoreApplication app{argc, argv};
QTimer ticker;
QObject::connect(&ticker, &QTimer::timeout, &app, []() {
std::cout << QDateTime::currentDateTime().toString(Qt::ISODateWithMs).toStdString()
<< " Secondary timer tick!" << std::endl;
});
ticker.start(200ms);
QTimer::singleShot(0, runMainTimer);
return app.exec();
}
|