From 8f4cf38d53945bb64cef5f54b31d14aeccf6cefe Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 17 Mar 2016 07:29:33 +0100 Subject: QQuickStyle: fix random crashes accessing deleted QQuickPopupItem Don't access QQuickPopupItem while being destroyed. The popup item is deleted in QQuickPopup destructor, which is the parent of QQuickStyle that is attached to a popup. We don't need to remove the listener in this case. Change-Id: I0e0dba533b3b1299eb0d266c92f3070bb193c6c9 Reviewed-by: J-P Nurmi --- src/controls/qquickstyle.cpp | 21 ++++++++------------- src/controls/qquickstyle_p.h | 2 -- 2 files changed, 8 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/controls/qquickstyle.cpp b/src/controls/qquickstyle.cpp index c38950d8..76cb24cc 100644 --- a/src/controls/qquickstyle.cpp +++ b/src/controls/qquickstyle.cpp @@ -145,14 +145,20 @@ static QList findChildStyles(const QMetaObject *type, QObject *ob QQuickStyle::QQuickStyle(QObject *parent) : QObject(parent) { - QQuickItem *item = parentItem(); + QQuickItem *item = qobject_cast(parent); + if (!item) { + QQuickPopup *popup = qobject_cast(parent); + if (popup) + item = popup->popupItem(); + } + if (item) QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); } QQuickStyle::~QQuickStyle() { - QQuickItem *item = parentItem(); + QQuickItem *item = qobject_cast(parent()); if (item) QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); @@ -174,17 +180,6 @@ QSharedPointer QQuickStyle::settings(const QString &group) return QSharedPointer(); } -QQuickItem *QQuickStyle::parentItem() const -{ - QQuickItem *item = qobject_cast(parent()); - if (!item) { - QQuickPopup *popup = qobject_cast(parent()); - if (popup) - item = popup->popupItem(); - } - return item; -} - QList QQuickStyle::childStyles() const { return m_childStyles; diff --git a/src/controls/qquickstyle_p.h b/src/controls/qquickstyle_p.h index c5bfed0f..02ee667a 100644 --- a/src/controls/qquickstyle_p.h +++ b/src/controls/qquickstyle_p.h @@ -72,8 +72,6 @@ public: protected: void init(); - QQuickItem *parentItem() const; - QList childStyles() const; QQuickStyle *parentStyle() const; -- cgit v1.2.3