From 1df4ebe0ef62fb8ce77db4cde001d4d52930f1cc Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 4 Jul 2013 09:55:32 +0200 Subject: [PATCH] Stabilize tst_QApplication::quitOnLastWindowClosed(). Instantiate widgets on the stack to ensure they are destroyed when the QApplication instance goes out of scope. Introduce waitForWindowExposed() to make sure events are in sync. Task-number: QTBUG-32125 Change-Id: Ia54e2fa9a7c2e279353c4514a6735e326edf35ae Reviewed-by: Shawn Rutledge --- .../kernel/qapplication/tst_qapplication.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index c9079e222c7..8d75298673e 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -694,18 +694,20 @@ void tst_QApplication::quitOnLastWindowClosed() QSignalSpy spy(&app, SIGNAL(aboutToQuit())); QSignalSpy spy2(&timer, SIGNAL(timeout())); - QPointer mainWindow = new QMainWindow; - QPointer dialog = new QDialog(mainWindow); + QMainWindow mainWindow; + QDialog *dialog = new QDialog(&mainWindow); QVERIFY(app.quitOnLastWindowClosed()); - QVERIFY(mainWindow->testAttribute(Qt::WA_QuitOnClose)); + QVERIFY(mainWindow.testAttribute(Qt::WA_QuitOnClose)); QVERIFY(dialog->testAttribute(Qt::WA_QuitOnClose)); - mainWindow->show(); + mainWindow.show(); + QVERIFY(QTest::qWaitForWindowExposed(&mainWindow)); dialog->show(); + QVERIFY(QTest::qWaitForWindowExposed(dialog)); timer.start(); - QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application + QTimer::singleShot(1000, &mainWindow, SLOT(close())); // This should quit the application QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't app.exec(); @@ -722,15 +724,16 @@ void tst_QApplication::quitOnLastWindowClosed() QSignalSpy spy(&app, SIGNAL(aboutToQuit())); QSignalSpy spy2(&timer, SIGNAL(timeout())); - QPointer mainWindow = new CloseEventTestWindow; + CloseEventTestWindow mainWindow; QVERIFY(app.quitOnLastWindowClosed()); - QVERIFY(mainWindow->testAttribute(Qt::WA_QuitOnClose)); + QVERIFY(mainWindow.testAttribute(Qt::WA_QuitOnClose)); - mainWindow->show(); + mainWindow.show(); + QVERIFY(QTest::qWaitForWindowExposed(&mainWindow)); timer.start(); - QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should quit the application + QTimer::singleShot(1000, &mainWindow, SLOT(close())); // This should quit the application QTimer::singleShot(2000, &app, SLOT(quit())); // This makes sure we quit even if it didn't app.exec();