diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-04-14 17:13:11 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-04-15 09:24:48 +0000 |
commit | b2e766c0cf4b5ae027f8d96202a9a9d29a7d84d4 (patch) | |
tree | 3973cf29c8cc6a2bbaf66b6b9a68f28e5935c1a1 /src/quicktemplates2/qquickscrollindicator.cpp | |
parent | 8ed4c6caf5fd464adf3c41192a97e47b48acb713 (diff) |
ScrollBar|Indicator: use QQmlInfo and don't crash with non-Flickables
Before:
ScrollBar must be attached to a Flickable QQuickItem(0x1774640)
The program has unexpectedly finished.
After:
qrc:/main.qml:9:5: QML : ScrollBar must be attached to a Flickable
Change-Id: I689d70744f64e209eacb4cb743ad64e904f29cd4
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/quicktemplates2/qquickscrollindicator.cpp')
-rw-r--r-- | src/quicktemplates2/qquickscrollindicator.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/quicktemplates2/qquickscrollindicator.cpp b/src/quicktemplates2/qquickscrollindicator.cpp index 56c78615..faf61905 100644 --- a/src/quicktemplates2/qquickscrollindicator.cpp +++ b/src/quicktemplates2/qquickscrollindicator.cpp @@ -37,6 +37,7 @@ #include "qquickscrollindicator_p.h" #include "qquickcontrol_p_p.h" +#include <QtQml/qqmlinfo.h> #include <QtQuick/private/qquickflickable_p.h> #include <QtQuick/private/qquickitemchangelistener_p.h> @@ -126,11 +127,10 @@ QQuickScrollIndicator::QQuickScrollIndicator(QQuickItem *parent) : QQuickScrollIndicatorAttached *QQuickScrollIndicator::qmlAttachedProperties(QObject *object) { QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(object); - if (flickable) - return new QQuickScrollIndicatorAttached(flickable); + if (!flickable) + qmlInfo(object) << "ScrollIndicator must be attached to a Flickable"; - qWarning() << "ScrollIndicator must be attached to a Flickable" << object; - return nullptr; + return new QQuickScrollIndicatorAttached(flickable); } /*! @@ -294,17 +294,21 @@ QQuickScrollIndicatorAttached::QQuickScrollIndicatorAttached(QQuickFlickable *fl QObject(*(new QQuickScrollIndicatorAttachedPrivate(flickable)), flickable) { Q_D(QQuickScrollIndicatorAttached); - QQuickItemPrivate *p = QQuickItemPrivate::get(flickable); - p->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + if (flickable) { + QQuickItemPrivate *p = QQuickItemPrivate::get(flickable); + p->updateOrAddGeometryChangeListener(d, QQuickItemPrivate::SizeChange); + } } QQuickScrollIndicatorAttached::~QQuickScrollIndicatorAttached() { Q_D(QQuickScrollIndicatorAttached); - if (d->horizontal) - QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); - if (d->vertical) - QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + if (d->flickable) { + if (d->horizontal) + QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + if (d->vertical) + QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); + } } /*! @@ -331,7 +335,7 @@ void QQuickScrollIndicatorAttached::setHorizontal(QQuickScrollIndicator *horizon if (d->horizontal == horizontal) return; - if (d->horizontal) { + if (d->horizontal && d->flickable) { QQuickItemPrivate::get(d->horizontal)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingHorizontallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateHorizontal); @@ -343,7 +347,7 @@ void QQuickScrollIndicatorAttached::setHorizontal(QQuickScrollIndicator *horizon d->horizontal = horizontal; - if (horizontal) { + if (horizontal && d->flickable) { if (!horizontal->parentItem()) horizontal->setParentItem(d->flickable); horizontal->setOrientation(Qt::Horizontal); @@ -387,7 +391,7 @@ void QQuickScrollIndicatorAttached::setVertical(QQuickScrollIndicator *vertical) if (d->vertical == vertical) return; - if (d->vertical) { + if (d->vertical && d->flickable) { QQuickItemPrivate::get(d->vertical)->removeItemChangeListener(d, QQuickItemPrivate::Geometry); QObjectPrivate::disconnect(d->flickable, &QQuickFlickable::movingVerticallyChanged, d, &QQuickScrollIndicatorAttachedPrivate::activateVertical); @@ -399,7 +403,7 @@ void QQuickScrollIndicatorAttached::setVertical(QQuickScrollIndicator *vertical) d->vertical = vertical; - if (vertical) { + if (vertical && d->flickable) { if (!vertical->parentItem()) vertical->setParentItem(d->flickable); vertical->setOrientation(Qt::Vertical); |