Try to stabilize tst_QApplication::abortQuitOnShow

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ø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
bb10
Volker Hilsheimer 2024-02-21 12:51:49 +01:00
parent b697de79b0
commit 576c9160b1
1 changed files with 15 additions and 1 deletions

View File

@ -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);
}