aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Rauter <matthias.rauter@qt.io>2023-11-06 10:23:28 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-11-08 20:46:17 +0000
commit4b738d7964ebbc0f6f98fa7fa9c158213a6948d9 (patch)
tree0119f942f90368c3c548d80da6d8ff1bc876efd1
parent8e65667896899652a6de89478d8e55f7c17e4097 (diff)
Destroy overlay in Popup destructor
Amends 434e19bede219c51af1213f2fc56bf2d6367e52e Fixes: QTBUG-117831 Pick-to: 6.5 Change-Id: Icc3cafdf83a5b772b7a227dd1954d8cb3210cb5b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 9ca4969307f312d2706eb63944a90b5d3e3b4f84) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quicktemplates/qquickpopup.cpp10
-rw-r--r--src/quicktemplates/qquickpopup_p_p.h2
-rw-r--r--tests/auto/quickcontrols/qquickdrawer/tst_qquickdrawer.cpp16
3 files changed, 20 insertions, 8 deletions
diff --git a/src/quicktemplates/qquickpopup.cpp b/src/quicktemplates/qquickpopup.cpp
index 2e04cd9c39..93c8595315 100644
--- a/src/quicktemplates/qquickpopup.cpp
+++ b/src/quicktemplates/qquickpopup.cpp
@@ -617,7 +617,7 @@ void QQuickPopupPrivate::finalizeExitTransition()
popupItem->setParentItem(nullptr);
popupItem->setVisible(false);
}
- destroyOverlay();
+ destroyDimmer();
if (hadActiveFocusBeforeExitTransition && window) {
// restore focus to the next popup in chain, or to the window content if there are no other popups open
@@ -884,7 +884,7 @@ void QQuickPopupPrivate::createOverlay()
resizeOverlay();
}
-void QQuickPopupPrivate::destroyOverlay()
+void QQuickPopupPrivate::destroyDimmer()
{
if (dimmer) {
qCDebug(lcDimmer) << "destroying dimmer" << dimmer;
@@ -900,7 +900,7 @@ void QQuickPopupPrivate::destroyOverlay()
void QQuickPopupPrivate::toggleOverlay()
{
- destroyOverlay();
+ destroyDimmer();
if (dim)
createOverlay();
}
@@ -1774,7 +1774,9 @@ void QQuickPopup::setParentItem(QQuickItem *parent)
if (parent) {
QObjectPrivate::connect(parent, &QQuickItem::windowChanged, d, &QQuickPopupPrivate::setWindow);
QQuickItemPrivate::get(d->parentItem)->addItemChangeListener(d, QQuickItemPrivate::Destroyed);
- } else if (!d->inDestructor) {
+ } else if (d->inDestructor) {
+ d->destroyDimmer();
+ } else {
// NOTE: if setParentItem is called from the dtor, this bypasses virtual dispatch and calls QQuickPopup::close() directly
close();
}
diff --git a/src/quicktemplates/qquickpopup_p_p.h b/src/quicktemplates/qquickpopup_p_p.h
index eabe2df001..eb48ce913e 100644
--- a/src/quicktemplates/qquickpopup_p_p.h
+++ b/src/quicktemplates/qquickpopup_p_p.h
@@ -93,7 +93,7 @@ public:
void reposition();
void createOverlay();
- void destroyOverlay();
+ void destroyDimmer();
void toggleOverlay();
void updateContentPalettes(const QPalette& parentPalette);
virtual void showOverlay();
diff --git a/tests/auto/quickcontrols/qquickdrawer/tst_qquickdrawer.cpp b/tests/auto/quickcontrols/qquickdrawer/tst_qquickdrawer.cpp
index cddaa8497f..ee0c6262d8 100644
--- a/tests/auto/quickcontrols/qquickdrawer/tst_qquickdrawer.cpp
+++ b/tests/auto/quickcontrols/qquickdrawer/tst_qquickdrawer.cpp
@@ -1441,14 +1441,24 @@ void tst_QQuickDrawer::touchOutsideOverlay() // QTBUG-103811
void tst_QQuickDrawer::destroyWhileVisible()
{
- QQuickView window;
- QVERIFY(QQuickTest::showView(window, testFileUrl("itemPartialOverlayModal.qml")));
- auto *drawer = window.rootObject()->findChild<QQuickDrawer*>();
+ QScopedPointer<QQuickView> window(new QQuickView());
+ QVERIFY(QQuickTest::showView(*window, testFileUrl("itemPartialOverlayModal.qml")));
+ auto *drawer = window->rootObject()->findChild<QQuickDrawer*>();
QVERIFY(drawer);
drawer->open();
QTRY_VERIFY(drawer->isOpened());
+
+ QQuickItem *dimmer = QQuickPopupPrivate::get(drawer)->dimmer;
+ QSignalSpy dimmerDeletedSpy(dimmer, &QObject::destroyed);
+
// don't crash here when the drawer closes with an exit transition
+ window.reset();
+
+ // make sure the dimmer is deleted
+ QTRY_COMPARE(dimmerDeletedSpy.size(), 1);
+
+
}
QTEST_QUICKCONTROLS_MAIN(tst_QQuickDrawer)