Qt Asynchronous Event Loop
This library integrates Boost.Coroutine2 into Qt.
You can await in an event loop, instead of creating QEventLoop
to wait
something done.
auto task = new qtael::Async([](const qtael::Await & await) -> void {
QNetworkAccessManager nasm;
QUrl url{"https://www.google.com/"};
QNetworkRequest request{url};
auto reply = nasm.get(request);
// NOTE yield to main event loop until the request finished
await(reply, &QNetworkReply::finished);
auto data = reply->readAll();
reply->deleteLater();
qDebug() << data;
});
// NOTE When the asynchronous function finished (i.e. reaches end or return),
// signal `finished()` will be emitted.
task->connect(task, SIGNAL(finished()), SLOT(deleteLater()));
// NOTE start this task, and it will not block the event loop
task->start();
mkdir build
cd build
cmake ..
make
make install