aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickrepeater.cpp
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2012-03-12 13:20:22 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-13 02:02:49 +0100
commitbe8675ab01132ffb03b81cc81842775d6a8fa3f9 (patch)
treeb7126d1fc348b8fe7393ebf646d5c92fa40c1cbc /src/quick/items/qquickrepeater.cpp
parentfc5ddb181896d3a364c046ae21b61283412fc722 (diff)
Change repeater item to handle model being deleted.
The repeater item previously stored a raw QObject pointer in a variant. When this pointer was a dynamic list model element that was deleted, the variant would continue to hold a stale pointer. Change repeater to use a guard object to hold the model when it is a QObject. Continue to use a variant to hold models that are not based on QObject to maintain same semantics. Change-Id: Ie100947132923803263c725e86efa68206382f12 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/quick/items/qquickrepeater.cpp')
-rw-r--r--src/quick/items/qquickrepeater.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/quick/items/qquickrepeater.cpp b/src/quick/items/qquickrepeater.cpp
index d26ebed85e..1f7578c583 100644
--- a/src/quick/items/qquickrepeater.cpp
+++ b/src/quick/items/qquickrepeater.cpp
@@ -51,7 +51,7 @@
QT_BEGIN_NAMESPACE
QQuickRepeaterPrivate::QQuickRepeaterPrivate()
- : model(0), ownModel(false), inRequest(false), itemCount(0), createFrom(-1)
+ : model(0), ownModel(false), inRequest(false), dataSourceIsObject(false), itemCount(0), createFrom(-1)
{
}
@@ -175,6 +175,12 @@ QQuickRepeater::~QQuickRepeater()
QVariant QQuickRepeater::model() const
{
Q_D(const QQuickRepeater);
+
+ if (d->dataSourceIsObject) {
+ QObject *o = d->dataSourceAsObject;
+ return QVariant::fromValue(o);
+ }
+
return d->dataSource;
}
@@ -194,6 +200,8 @@ void QQuickRepeater::setModel(const QVariant &model)
}
d->dataSource = model;
QObject *object = qvariant_cast<QObject*>(model);
+ d->dataSourceAsObject = object;
+ d->dataSourceIsObject = object != 0;
QQuickVisualModel *vim = 0;
if (object && (vim = qobject_cast<QQuickVisualModel *>(object))) {
if (d->ownModel) {