From 576c9160b12ac5efc76d06ca7ccc856aad2b051a Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 21 Feb 2024 12:51:49 +0100 Subject: [PATCH] Try to stabilize tst_QApplication::abortQuitOnShow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test has been very flaky recently. A zero timer might be processed before the window became visible, so only start closing once the window has been shown. Pick-to: 6.7 6.6 Change-Id: If7983723bb8abd2f3495fb21114c517289ebe8d9 Reviewed-by: Tor Arne Vestbø Reviewed-by: Qt CI Bot --- .../kernel/qapplication/tst_qapplication.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 2d0758bfde..52fdc63e08 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -2574,10 +2574,22 @@ public: explicit ShowCloseShowWidget(bool showAgain, QWidget *parent = nullptr) : QWidget(parent), showAgain(showAgain) { - QTimer::singleShot(0, this, &ShowCloseShowWidget::doClose); QTimer::singleShot(500, this, [] () { QCoreApplication::exit(1); }); } + bool shown = false; + +protected: + void showEvent(QShowEvent *) override + { + QTimer::singleShot(0, this, &ShowCloseShowWidget::doClose); + shown = true; + } + void hideEvent(QHideEvent *) override + { + shown = false; + } + private slots: void doClose() { close(); @@ -2596,11 +2608,13 @@ void tst_QApplication::abortQuitOnShow() ShowCloseShowWidget window1(false); window1.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window1.show(); + QVERIFY(QTest::qWaitFor([&window1](){ return window1.shown; })); QCOMPARE(QCoreApplication::exec(), 0); ShowCloseShowWidget window2(true); window2.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window2.show(); + QVERIFY(QTest::qWaitFor([&window2](){ return window2.shown; })); QCOMPARE(QCoreApplication::exec(), 1); }