summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-13 15:36:08 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-18 19:06:48 +0200
commitacb86da793c603991da63ba6ab7c6684518d0cd2 (patch)
tree76977ba20507c92cd7f46875cc431ddd5355a2c4 /tests/auto
parent826fc8c9bd0b7dabb58e0b278b52c5d9f7a7efd9 (diff)
Prevent recursive calls to QWindow::close
QWidget will call close() in its destructor, which we might end up in if a user deletes the widget in the closeEvent. Pick-to: 6.2 Change-Id: I39684aec0ca130033dad60f2bbf823364a5edcec Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 67ea378c66..9e8e1eac11 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -1602,6 +1602,23 @@ void tst_QWindow::sizes()
QCOMPARE(maximumHeightSpy.count(), 1);
}
+class CloseOnCloseEventWindow : public QWindow
+{
+public:
+ inline static int closeEvents;
+ CloseOnCloseEventWindow() { closeEvents = 0; }
+
+protected:
+ void closeEvent(QCloseEvent *e) override
+ {
+ if (++closeEvents > 1)
+ return;
+
+ close();
+ e->accept();
+ }
+};
+
void tst_QWindow::close()
{
{
@@ -1683,6 +1700,16 @@ void tst_QWindow::close()
QVERIFY(c.handle());
}
}
+
+ {
+ // A QWidget will call close() from the destructor, and
+ // we allow widgets deleting itself in the closeEvent,
+ // so we need to guard against close being called recursively.
+ CloseOnCloseEventWindow w;
+ w.create();
+ w.close();
+ QCOMPARE(CloseOnCloseEventWindow::closeEvents, 1);
+ }
}
void tst_QWindow::activateAndClose()