aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickstackview.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-07-15 16:43:17 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-07-18 20:02:34 +0000
commit8a1eb34740bc5bc4db4972ab2b2a8e738dca979a (patch)
tree44923f622213dc8ae0d284f28653ea717b8d184e /src/quicktemplates2/qquickstackview.cpp
parent65b323fdba1d6567c73229997f6ce0784dfc8427 (diff)
StackView: don't crash if attached to a non-Item
Change-Id: Ifa7ef9b0960494df917f9f60bf8d94cbee0f4661 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickstackview.cpp')
-rw-r--r--src/quicktemplates2/qquickstackview.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp
index 2aff2c38..df163089 100644
--- a/src/quicktemplates2/qquickstackview.cpp
+++ b/src/quicktemplates2/qquickstackview.cpp
@@ -289,12 +289,7 @@ QQuickStackView::~QQuickStackView()
QQuickStackAttached *QQuickStackView::qmlAttachedProperties(QObject *object)
{
- QQuickItem *item = qobject_cast<QQuickItem *>(object);
- if (!item) {
- qmlInfo(object) << "StackView must be attached to an Item";
- return nullptr;
- }
- return new QQuickStackAttached(item);
+ return new QQuickStackAttached(object);
}
/*!
@@ -993,19 +988,25 @@ void QQuickStackAttachedPrivate::itemParentChanged(QQuickItem *item, QQuickItem
emit q->statusChanged();
}
-QQuickStackAttached::QQuickStackAttached(QQuickItem *parent) :
+QQuickStackAttached::QQuickStackAttached(QObject *parent) :
QObject(*(new QQuickStackAttachedPrivate), parent)
{
Q_D(QQuickStackAttached);
- QQuickItemPrivate::get(parent)->addItemChangeListener(d, QQuickItemPrivate::Parent);
- d->itemParentChanged(parent, parent->parentItem());
+ QQuickItem *item = qobject_cast<QQuickItem *>(parent);
+ if (item) {
+ QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent);
+ d->itemParentChanged(item, item->parentItem());
+ } else if (parent) {
+ qmlInfo(parent) << "StackView must be attached to an Item";
+ }
}
QQuickStackAttached::~QQuickStackAttached()
{
Q_D(QQuickStackAttached);
- QQuickItem *parentItem = static_cast<QQuickItem *>(parent());
- QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
+ QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
+ if (parentItem)
+ QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
}
/*!