summaryrefslogtreecommitdiffstats
path: root/tests/manual/wasm/eventloop/asyncify_exec/main.cpp
blob: c3a827ac115b93ce3975b7c4dd405b227c348d91 (plain)
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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore>

// This test shows how to asyncify enables blocking
// the main thread on QEventLoop::exec(), while event
// provessing continues.
int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

#ifdef QT_HAVE_EMSCRIPTEN_ASYNCIFY
    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()";
    });
#else
        qDebug() << "This test requires Emscripten asyncify. To enable,"
                 << "configure Qt with -device-option QT_EMSCRIPTEN_ASYNCIFY=1";
#endif

    app.exec();
}