diff options
author | Michal Policht <michpolicht@gmail.com> | 2019-02-06 14:58:59 +0100 |
---|---|---|
committer | Michal Policht <michpolicht@gmail.com> | 2019-02-13 16:46:19 +0000 |
commit | 1e3ed172f35abaa0e0af43ee22259bc3cd188ad8 (patch) | |
tree | ac538d38b83874cb0647a263bae1f0e99b88fefc /tests/auto/qml/qqmlapplicationengine | |
parent | 01f9c623ed2dc1645ac022d69062f720e3b50132 (diff) |
Connect quit() and exit() signals with queued connections
Class QQmlApplicationEngine connects QQmlApplicationEngine::quit()
signal to QCoreApplication::quit() and QQmlApplicationEngine::exit()
signal to QCoreApplication::exit(), but it does so with AutoConnection.
This causes in some circumstances problems, which are described in Qt
documentation (see QCoreApplication::exit()). This change modifies type
of connections to queued connections.
[ChangeLog][QtQml][QQmlApplicationEngine] QQmlApplicationEngine
connects quit() and exit() signals with queued connections to avoid
problems with AutoConnection, when connecting to QCoreApplication
slots.
Task-number: QTBUG-73649
Change-Id: Ib27738b5af2f879efee8862b1ca01613a2e8dc4e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlapplicationengine')
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/testapp/delayedExit.qml | 11 | ||||
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/testapp/delayedQuit.qml (renamed from tests/auto/qml/qqmlapplicationengine/testapp/main.qml) | 0 | ||||
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/testapp/immediateExit.qml | 8 | ||||
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/testapp/immediateQuit.qml | 8 | ||||
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/testapp/main.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/testapp/main.qrc | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp | 44 |
7 files changed, 65 insertions, 13 deletions
diff --git a/tests/auto/qml/qqmlapplicationengine/testapp/delayedExit.qml b/tests/auto/qml/qqmlapplicationengine/testapp/delayedExit.qml new file mode 100644 index 0000000000..3d67c958bb --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/testapp/delayedExit.qml @@ -0,0 +1,11 @@ +import QtQml 2.0 + +QtObject { + id: root + property Timer t: Timer { interval: 1; running: true; onTriggered: Qt.exit(0); } + property Connections c: Connections { + target: Qt.application + onAboutToQuit: console.log("End"); + } + Component.onCompleted: console.log("Start: " + Qt.application.arguments[1]); +} diff --git a/tests/auto/qml/qqmlapplicationengine/testapp/main.qml b/tests/auto/qml/qqmlapplicationengine/testapp/delayedQuit.qml index c75485a7f7..c75485a7f7 100644 --- a/tests/auto/qml/qqmlapplicationengine/testapp/main.qml +++ b/tests/auto/qml/qqmlapplicationengine/testapp/delayedQuit.qml diff --git a/tests/auto/qml/qqmlapplicationengine/testapp/immediateExit.qml b/tests/auto/qml/qqmlapplicationengine/testapp/immediateExit.qml new file mode 100644 index 0000000000..46634f3f51 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/testapp/immediateExit.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 + +QtObject { + Component.onCompleted: { + console.log("End: " + Qt.application.arguments[1]); + Qt.exit(0) + } +} diff --git a/tests/auto/qml/qqmlapplicationengine/testapp/immediateQuit.qml b/tests/auto/qml/qqmlapplicationengine/testapp/immediateQuit.qml new file mode 100644 index 0000000000..1da9d1201a --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/testapp/immediateQuit.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 + +QtObject { + Component.onCompleted: { + console.log("End: " + Qt.application.arguments[1]); + Qt.quit() + } +} diff --git a/tests/auto/qml/qqmlapplicationengine/testapp/main.cpp b/tests/auto/qml/qqmlapplicationengine/testapp/main.cpp index a57889fe86..be0d98a2df 100644 --- a/tests/auto/qml/qqmlapplicationengine/testapp/main.cpp +++ b/tests/auto/qml/qqmlapplicationengine/testapp/main.cpp @@ -32,6 +32,6 @@ int main (int argc, char *argv[]) { QCoreApplication app(argc, argv); - QQmlApplicationEngine e(QUrl("qrc:///main.qml")); + QQmlApplicationEngine e(QUrl(QString("qrc:///") + argv[1])); return app.exec(); } diff --git a/tests/auto/qml/qqmlapplicationengine/testapp/main.qrc b/tests/auto/qml/qqmlapplicationengine/testapp/main.qrc index 5f6483ac33..82b695bbd8 100644 --- a/tests/auto/qml/qqmlapplicationengine/testapp/main.qrc +++ b/tests/auto/qml/qqmlapplicationengine/testapp/main.qrc @@ -1,5 +1,8 @@ <RCC> <qresource prefix="/"> - <file>main.qml</file> + <file>immediateQuit.qml</file> + <file>immediateExit.qml</file> + <file>delayedQuit.qml</file> + <file>delayedExit.qml</file> </qresource> </RCC> diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index daeb9b5455..ce654dc45e 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -46,6 +46,7 @@ private slots: void initTestCase(); void basicLoading(); void testNonResolvedPath(); + void application_data(); void application(); void applicationProperties(); void removeObjectsWhenDestroyed(); @@ -111,35 +112,56 @@ void tst_qqmlapplicationengine::testNonResolvedPath() } } +void tst_qqmlapplicationengine::application_data() +{ + QTest::addColumn<QByteArray>("qmlFile"); + QTest::addColumn<QByteArray>("expectedStdErr"); + + QTest::newRow("delayed quit") << QByteArray("delayedQuit.qml") + << QByteArray("qml: Start: delayedQuit.qml\nqml: End\n"); + QTest::newRow("delayed exit") << QByteArray("delayedExit.qml") + << QByteArray("qml: Start: delayedExit.qml\nqml: End\n"); + QTest::newRow("immediate quit") << QByteArray("immediateQuit.qml") + << QByteArray("qml: End: immediateQuit.qml\n"); + QTest::newRow("immediate exit") << QByteArray("immediateExit.qml") + << QByteArray("qml: End: immediateExit.qml\n"); +} + void tst_qqmlapplicationengine::application() { /* This test batches together some tests about running an external application written with QQmlApplicationEngine. The application tests the following functionality which is easier to do by watching a separate process: - -Loads relative paths from the working directory - -quits when quit is called - -emits aboutToQuit after quit is called - -has access to application command line arguments + - Loads relative paths from the working directory + - Quits when quit is called + - Exits when exit is called + - Emits aboutToQuit after quit is called + - Has access to application command line arguments Note that checking the output means that on builds with extra debugging, this might fail with a false positive. Also the testapp is automatically built and installed in shadow builds, so it does NOT use testData */ + + QFETCH(QByteArray, qmlFile); + QFETCH(QByteArray, expectedStdErr); + #if QT_CONFIG(process) QDir::setCurrent(buildDir); QProcess *testProcess = new QProcess(this); QStringList args; - args << QLatin1String("testData"); + args << qmlFile; // QML file passed as an argument is going to be run by testapp. testProcess->start(QLatin1String("testapp/testapp"), args); QVERIFY(testProcess->waitForFinished(5000)); QCOMPARE(testProcess->exitCode(), 0); - QByteArray test_stdout = testProcess->readAllStandardOutput(); - QByteArray test_stderr = testProcess->readAllStandardError(); - QByteArray test_stderr_target("qml: Start: testData\nqml: End\n"); + QByteArray testStdOut = testProcess->readAllStandardOutput(); + QByteArray testStdErr = testProcess->readAllStandardError(); #ifdef Q_OS_WIN - test_stderr_target.replace('\n', QByteArray("\r\n")); + expectedStdErr.replace('\n', QByteArray("\r\n")); #endif - QCOMPARE(test_stdout, QByteArray("")); - QVERIFY(QString(test_stderr).endsWith(QString(test_stderr_target))); + QCOMPARE(testStdOut, QByteArray("")); + QVERIFY2(QString(testStdErr).endsWith(QString(expectedStdErr)), + QByteArray("\nExpected ending:\n") + expectedStdErr + + QByteArray("\nActual output:\n") + testStdErr); delete testProcess; QDir::setCurrent(srcDir); #else // process |