diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-17 07:29:33 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-17 09:40:53 +0000 |
commit | 8f4cf38d53945bb64cef5f54b31d14aeccf6cefe (patch) | |
tree | 5106d625bed5d153f3b5cbc89ed35c64a49765f7 /src/controls | |
parent | 9799a28e1d00a6a72fd813e97ef3cd0ede8ba746 (diff) |
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 <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/controls')
-rw-r--r-- | src/controls/qquickstyle.cpp | 21 | ||||
-rw-r--r-- | src/controls/qquickstyle_p.h | 2 |
2 files changed, 8 insertions, 15 deletions
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<QQuickStyle *> findChildStyles(const QMetaObject *type, QObject *ob QQuickStyle::QQuickStyle(QObject *parent) : QObject(parent) { - QQuickItem *item = parentItem(); + QQuickItem *item = qobject_cast<QQuickItem *>(parent); + if (!item) { + QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent); + if (popup) + item = popup->popupItem(); + } + if (item) QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); } QQuickStyle::~QQuickStyle() { - QQuickItem *item = parentItem(); + QQuickItem *item = qobject_cast<QQuickItem *>(parent()); if (item) QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); @@ -174,17 +180,6 @@ QSharedPointer<QSettings> QQuickStyle::settings(const QString &group) return QSharedPointer<QSettings>(); } -QQuickItem *QQuickStyle::parentItem() const -{ - QQuickItem *item = qobject_cast<QQuickItem *>(parent()); - if (!item) { - QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent()); - if (popup) - item = popup->popupItem(); - } - return item; -} - QList<QQuickStyle *> 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<QQuickStyle *> childStyles() const; QQuickStyle *parentStyle() const; |