qt5base-lts/tests/manual/wasm/eventloop/asyncify_exec/main.cpp
Morten Sørvig f347682fd5 wasm: include asyncify support unconditionally
Emscripten's option for enabling asyncify (-sASYNCIFY) is a link-time
option, which means there is no requirement to have a separate asyncify
build, at least for static builds.

Replace the current QT_HAVE_EMSCRIPTEN_ASYNCIFY compile-time option
with a run-time option which checks if the asyncify API is available.

Keep support for configuring with "-device-option QT_EMSCRIPTEN_ASYNCIFY=1"
for backwards compatibility and for the use case where want asyncify
support to be on by default for a given Qt build.

Enable asyncify for the asyncify_exec example.

Pick-to: 6.4
Change-Id: I301fd7e2d3c0367532c886f4e34b23e1093646ad
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-08-17 04:52:46 +02:00

26 lines
690 B
C++

// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore>
// This test shows how to use asyncify to enable blocking the main
// thread on QEventLoop::exec(), while event processing continues.
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QTimer::singleShot(1000, []() {
QEventLoop loop;
QTimer::singleShot(2000, [&loop]() {
qDebug() << "Calling QEventLoop::quit()";
loop.quit();
});
qDebug() << "Calling QEventLoop::exec()";
loop.exec();
qDebug() << "Returned from QEventLoop::exec()";
});
app.exec();
}