summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-09-06 14:32:39 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-06 19:00:34 +0000
commita22a216d18b81a57b936253705d95b77ac46a492 (patch)
treea773892e5dc67c1ad965ca05b1e3b04759437b5f
parent3a6d5f2b946215866136ab20403a4f53a74af6fe (diff)
Add test-case for QWidget closing exits event loop
Also when closed by destruction, which as of today doesn't call QWidget::close and therefore also not QWindow::close. Change-Id: I426255e2274eae9262243c769df2264fbaa915b0 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 7c85ad307b1c9d69b4a9e5424f111d031649c44a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 7ca08993ab..21e77378d1 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -52,6 +52,7 @@
#include <qmainwindow.h>
#include <qdockwidget.h>
#include <qrandom.h>
+#include <qsignalspy.h>
#include <qstylehints.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
@@ -425,6 +426,7 @@ private slots:
void receivesApplicationFontChangeEvent();
void receivesApplicationPaletteChangeEvent();
void deleteWindowInCloseEvent();
+ void quitOnClose();
private:
bool ensureScreenSize(int width, int height);
@@ -11946,5 +11948,34 @@ void tst_QWidget::deleteWindowInCloseEvent()
QVERIFY(true);
}
+/*!
+ Verify that both closing and deleting the last (only) window-widget
+ exits the application event loop.
+*/
+void tst_QWidget::quitOnClose()
+{
+ QSignalSpy quitSpy(qApp, &QApplication::lastWindowClosed);
+
+ std::unique_ptr<QWidget>widget(new QWidget);
+ widget->show();
+ QVERIFY(QTest::qWaitForWindowExposed(widget.get()));
+
+ // QGuiApplication::lastWindowClosed is documented to only be emitted
+ // when we are in exec()
+ QTimer::singleShot(0, widget.get(), [&]{
+ widget->close();
+ });
+ QApplication::exec();
+ QCOMPARE(quitSpy.count(), 1);
+
+ widget->show();
+ QVERIFY(QTest::qWaitForWindowExposed(widget.get()));
+ QTimer::singleShot(0, widget.get(), [&]{
+ widget.reset();
+ });
+ QApplication::exec();
+ QCOMPARE(quitSpy.count(), 2);
+}
+
QTEST_MAIN(tst_QWidget)
#include "tst_qwidget.moc"