diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2020-06-05 09:48:52 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2020-08-17 10:13:55 +0200 |
commit | 3a5a2408266ec47f350a89419f1ec618442c1d60 (patch) | |
tree | a796369f78d6071a4b7fc4c80a1e342ae6ab1d7b /src/quicktemplates2/qquickpopupanchors.cpp | |
parent | 8e6d16ff303911bf2a93cf4e8e794f125a06d2b0 (diff) |
Fix crash on exit when centering Popup within Overlay in StackView item
If a Popup is centered within an Overlay, and that Overlay is destroyed
before the Popup, we must make sure centerIn is cleared so we don't try
to access a dangling pointer.
Fixes: QTBUG-84579
Change-Id: Icb2750f847f9d5710725bedc4d1c92bf4c122c03
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 04901b170e009d844232067446fdd56f270d155d)
Diffstat (limited to 'src/quicktemplates2/qquickpopupanchors.cpp')
-rw-r--r-- | src/quicktemplates2/qquickpopupanchors.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickpopupanchors.cpp b/src/quicktemplates2/qquickpopupanchors.cpp index 5acc2934..c7ac038d 100644 --- a/src/quicktemplates2/qquickpopupanchors.cpp +++ b/src/quicktemplates2/qquickpopupanchors.cpp @@ -47,6 +47,15 @@ QQuickPopupAnchors::QQuickPopupAnchors(QQuickPopup *popup) d->popup = popup; } +QQuickPopupAnchors::~QQuickPopupAnchors() +{ + Q_D(const QQuickPopupAnchors); + if (d->centerIn) { + auto centerInPrivate = QQuickItemPrivate::get(d->centerIn); + centerInPrivate->removeItemChangeListener(this, QQuickItemPrivate::Destroyed); + } +} + QQuickItem *QQuickPopupAnchors::centerIn() const { Q_D(const QQuickPopupAnchors); @@ -59,8 +68,20 @@ void QQuickPopupAnchors::setCenterIn(QQuickItem *item) if (item == d->centerIn) return; + if (d->centerIn) { + auto centerInPrivate = QQuickItemPrivate::get(d->centerIn); + centerInPrivate->removeItemChangeListener(this, QQuickItemPrivate::Destroyed); + } + d->centerIn = item; + + if (d->centerIn) { + auto centerInPrivate = QQuickItemPrivate::get(d->centerIn); + centerInPrivate->addItemChangeListener(this, QQuickItemPrivate::Destroyed); + } + QQuickPopupPrivate::get(d->popup)->reposition(); + emit centerInChanged(); } @@ -69,4 +90,9 @@ void QQuickPopupAnchors::resetCenterIn() setCenterIn(nullptr); } +void QQuickPopupAnchors::itemDestroyed(QQuickItem *) +{ + resetCenterIn(); +} + QT_END_NAMESPACE |