diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-11 01:56:34 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-11 01:56:34 (GMT) |
commit | 5c69031b23f349d199ed43e484a608a2b691bb95 (patch) | |
tree | 58ab03fddc0df3416c2740231c04a823e677cf41 /src | |
parent | 97383f0f253a3696dd9a75338aa7d263b05526e1 (diff) | |
download | Qt-5c69031b23f349d199ed43e484a608a2b691bb95.zip Qt-5c69031b23f349d199ed43e484a608a2b691bb95.tar.gz Qt-5c69031b23f349d199ed43e484a608a2b691bb95.tar.bz2 |
When a QmlContext is destroyed, associated objects must be disassociated
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlcontext.cpp | 12 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmldeclarativedata_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 14 |
5 files changed, 25 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index dfcf413..16399bc 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -231,6 +231,18 @@ QmlContext::QmlContext(QmlContext *parentContext, QObject *parent) */ QmlContext::~QmlContext() { + Q_D(QmlContext); + for(int ii = 0; ii < d->contextObjects.count(); ++ii) { + QObjectPrivate *p = QObjectPrivate::get(d->contextObjects.at(ii)); + QmlSimpleDeclarativeData *data = + static_cast<QmlSimpleDeclarativeData *>(p->declarativeData); + if(data && (data->flags & QmlSimpleDeclarativeData::Extended)) { + data->context = 0; + } else { + p->declarativeData = 0; + } + } + d->contextObjects.clear(); } diff --git a/src/declarative/qml/qmlcontext.h b/src/declarative/qml/qmlcontext.h index 39d565a..935c7ca 100644 --- a/src/declarative/qml/qmlcontext.h +++ b/src/declarative/qml/qmlcontext.h @@ -95,6 +95,7 @@ private: friend class QmlComponent; friend class QmlScriptPrivate; friend class QmlBoundSignalProxy; + friend class QmlSimpleDeclarativeData; QmlContext(QmlEngine *); }; diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index d7c6d29..9faa7b7 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -88,6 +88,7 @@ public: void addDefaultObject(QObject *, Priority); QmlSimpleDeclarativeData contextData; + QObjectList contextObjects; }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmldeclarativedata_p.h b/src/declarative/qml/qmldeclarativedata_p.h index a934442..fb7a015 100644 --- a/src/declarative/qml/qmldeclarativedata_p.h +++ b/src/declarative/qml/qmldeclarativedata_p.h @@ -51,6 +51,7 @@ class QmlSimpleDeclarativeData : public QDeclarativeData public: QmlSimpleDeclarativeData() : flags(0), context(0) {} + virtual void destroyed(QObject *); enum Flag { Extended = 0x00000001 }; quint32 flags; QmlContext *context; diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index f0ec334..fc209c6 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -659,11 +659,10 @@ void QmlEngine::setContextForObject(QObject *object, QmlContext *context) if (!data) { priv->declarativeData = &context->d_func()->contextData; } else { - // ### - Don't have to use extended data here - QmlExtendedDeclarativeData *data = new QmlExtendedDeclarativeData; data->context = context; - priv->declarativeData = data; } + + context->d_func()->contextObjects.append(object); } QmlContext *qmlContext(const QObject *obj) @@ -713,8 +712,15 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object) return rv; } -void QmlExtendedDeclarativeData::destroyed(QObject *) +void QmlSimpleDeclarativeData::destroyed(QObject *object) +{ + if (context) + context->d_func()->contextObjects.removeAll(object); +} + +void QmlExtendedDeclarativeData::destroyed(QObject *object) { + QmlSimpleDeclarativeData::destroyed(object); delete this; } |