aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-01-19 23:40:38 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-01-20 09:05:20 +0000
commit318106e54f5b6f86f4eeb477da892f55d3234bef (patch)
treed7b98adac7656e13ee430c6fcf9a11b8ee01ca25 /src
parente10b4acd4a60182d175b06b461f7b6aef15567dd (diff)
ScrollIndicator: fix memory leak when attached to a non-Flickable
We must pass the attachee QObject as a parent instead of passing a qobject_casted QQuickFlickable, which may be a null pointer. Change-Id: I2e229ff59363246fc4515b1c7cbf1850dd2b1d43 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickscrollindicator.cpp23
-rw-r--r--src/quicktemplates2/qquickscrollindicator_p.h2
2 files changed, 11 insertions, 14 deletions
diff --git a/src/quicktemplates2/qquickscrollindicator.cpp b/src/quicktemplates2/qquickscrollindicator.cpp
index 8080d325..05ec2063 100644
--- a/src/quicktemplates2/qquickscrollindicator.cpp
+++ b/src/quicktemplates2/qquickscrollindicator.cpp
@@ -174,11 +174,7 @@ QQuickScrollIndicator::QQuickScrollIndicator(QQuickItem *parent)
QQuickScrollIndicatorAttached *QQuickScrollIndicator::qmlAttachedProperties(QObject *object)
{
- QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(object);
- if (!flickable)
- qmlWarning(object) << "ScrollIndicator must be attached to a Flickable";
-
- return new QQuickScrollIndicatorAttached(flickable);
+ return new QQuickScrollIndicatorAttached(object);
}
/*!
@@ -298,8 +294,8 @@ void QQuickScrollIndicator::setOrientation(Qt::Orientation orientation)
class QQuickScrollIndicatorAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener
{
public:
- QQuickScrollIndicatorAttachedPrivate(QQuickFlickable *flickable)
- : flickable(flickable),
+ QQuickScrollIndicatorAttachedPrivate()
+ : flickable(nullptr),
horizontal(nullptr),
vertical(nullptr)
{
@@ -379,14 +375,15 @@ void QQuickScrollIndicatorAttachedPrivate::itemDestroyed(QQuickItem *item)
vertical = nullptr;
}
-QQuickScrollIndicatorAttached::QQuickScrollIndicatorAttached(QQuickFlickable *flickable)
- : QObject(*(new QQuickScrollIndicatorAttachedPrivate(flickable)), flickable)
+QQuickScrollIndicatorAttached::QQuickScrollIndicatorAttached(QObject *parent)
+ : QObject(*(new QQuickScrollIndicatorAttachedPrivate), parent)
{
Q_D(QQuickScrollIndicatorAttached);
- if (flickable) {
- QQuickItemPrivate *p = QQuickItemPrivate::get(flickable);
- p->updateOrAddGeometryChangeListener(d, QQuickGeometryChange::Size);
- }
+ d->flickable = qobject_cast<QQuickFlickable *>(parent);
+ if (d->flickable)
+ QQuickItemPrivate::get(d->flickable)->updateOrAddGeometryChangeListener(d, QQuickGeometryChange::Size);
+ else if (parent)
+ qmlWarning(parent) << "ScrollIndicator must be attached to a Flickable";
}
QQuickScrollIndicatorAttached::~QQuickScrollIndicatorAttached()
diff --git a/src/quicktemplates2/qquickscrollindicator_p.h b/src/quicktemplates2/qquickscrollindicator_p.h
index 13be7394..c4408500 100644
--- a/src/quicktemplates2/qquickscrollindicator_p.h
+++ b/src/quicktemplates2/qquickscrollindicator_p.h
@@ -107,7 +107,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollIndicatorAttached : public QO
Q_PROPERTY(QQuickScrollIndicator *vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL)
public:
- explicit QQuickScrollIndicatorAttached(QQuickFlickable *flickable);
+ explicit QQuickScrollIndicatorAttached(QObject *parent = nullptr);
~QQuickScrollIndicatorAttached();
QQuickScrollIndicator *horizontal() const;