diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-11 02:13:04 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-05-11 02:13:04 (GMT) |
commit | b9f263eb1e5871ed724452e7454b8414e554ead6 (patch) | |
tree | ce75abbd158d74f7152126ca9311ee268c370942 /src/declarative/qml/qmlcontext.cpp | |
parent | 5c69031b23f349d199ed43e484a608a2b691bb95 (diff) | |
download | Qt-b9f263eb1e5871ed724452e7454b8414e554ead6.zip Qt-b9f263eb1e5871ed724452e7454b8414e554ead6.tar.gz Qt-b9f263eb1e5871ed724452e7454b8414e554ead6.tar.bz2 |
Clean up QmlContext's and QmlExpression's when a context gets deleted
Diffstat (limited to 'src/declarative/qml/qmlcontext.cpp')
-rw-r--r-- | src/declarative/qml/qmlcontext.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 16399bc..df5f90e 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -86,6 +86,10 @@ void QmlContextPrivate::destroyed(QObject *obj) void QmlContextPrivate::init() { Q_Q(QmlContext); + + if (parent) + parent->d_func()->childContexts.insert(q); + //set scope chain QScriptEngine *scriptEngine = engine->scriptEngine(); QScriptValue scopeObj = @@ -232,7 +236,24 @@ QmlContext::QmlContext(QmlContext *parentContext, QObject *parent) QmlContext::~QmlContext() { Q_D(QmlContext); - for(int ii = 0; ii < d->contextObjects.count(); ++ii) { + if (d->parent) + d->parent->d_func()->childContexts.remove(this); + + for (QSet<QmlContext *>::ConstIterator iter = d->childContexts.begin(); + iter != d->childContexts.end(); + ++iter) { + (*iter)->d_func()->invalidateEngines(); + (*iter)->d_func()->parent = 0; + } + + for (QSet<QmlExpression *>::ConstIterator iter = + d->childExpressions.begin(); + iter != d->childExpressions.end(); + ++iter) { + (*iter)->d->ctxt = 0; + } + + for (int ii = 0; ii < d->contextObjects.count(); ++ii) { QObjectPrivate *p = QObjectPrivate::get(d->contextObjects.at(ii)); QmlSimpleDeclarativeData *data = static_cast<QmlSimpleDeclarativeData *>(p->declarativeData); @@ -245,6 +266,17 @@ QmlContext::~QmlContext() d->contextObjects.clear(); } +void QmlContextPrivate::invalidateEngines() +{ + if (!engine) + return; + engine = 0; + for (QSet<QmlContext *>::ConstIterator iter = childContexts.begin(); + iter != childContexts.end(); + ++iter) { + (*iter)->d_func()->invalidateEngines(); + } +} /*! Return the context's QmlEngine, or 0 if the context has no QmlEngine or the |