From e52a73d8c74576e267dcc59d42247bd14131daaf Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 14 Apr 2010 16:16:07 +1000 Subject: Reduce warnings at shutdown QTBUG-9799 --- src/declarative/qml/qdeclarativebinding.cpp | 2 +- src/declarative/qml/qdeclarativecompiledbindings.cpp | 5 +---- src/declarative/qml/qdeclarativecontext_p.h | 4 ++++ src/declarative/qml/qdeclarativeengine.cpp | 6 +++--- src/declarative/qml/qdeclarativeexpression.cpp | 2 +- .../data/noSpuriousWarningsAtShutdown.qml | 9 +++++++++ .../tst_qdeclarativeecmascript.cpp | 18 ++++++++++++++++++ 7 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.qml diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index e172a8b..664118d 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -126,7 +126,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) QDeclarativeBindingData *data = d->bindingData(); - if (!data->enabled || !data->context() || !data->context()->engine) + if (!data->enabled || !data->context() || !data->context()->isValid()) return; data->addref(); diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index bbce8a6..6fdf706 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -285,10 +285,7 @@ void QDeclarativeCompiledBindingsPrivate::run(Binding *binding, QDeclarativeProp return; QDeclarativeContextData *context = q->QDeclarativeAbstractExpression::context(); - if (!context) - return; - - if (!context->engine) + if (!context || !context->isValid()) return; if (binding->updating) { diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index eee72b6..6059f72 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -114,6 +114,10 @@ public: QDeclarativeContextData(QDeclarativeContext *); void destroy(); + inline bool isValid() const { + return engine && (!isInternal || contextObject && !QObjectPrivate::get(contextObject)->wasDeleted); + } + // My parent context and engine QDeclarativeContextData *parent; QDeclarativeEngine *engine; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 8462c65..f621af5 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -851,6 +851,9 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) if (propertyCache) propertyCache->release(); + if (ownContext) + context->destroy(); + QDeclarativeGuard *guard = guards; while (guard) { QDeclarativeGuard *g = guard; @@ -861,9 +864,6 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) g->objectDestroyed(object); } - if (ownContext) - context->destroy(); - if (scriptValue) delete scriptValue; diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 2a3e557..05240a2 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -468,7 +468,7 @@ QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isU { Q_Q(QDeclarativeExpression); - if (!q->engine()) { + if (!data || !data->context() || !data->context()->isValid()) { qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context"); return QVariant(); } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.qml b/tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.qml new file mode 100644 index 0000000..a52c772 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/noSpuriousWarningsAtShutdown.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +Item { + id: root + + property int childrenCount: root.children.length + + Item {} +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index c648de4..12a065e 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -142,6 +142,7 @@ private slots: void libraryScriptAssert(); void variantsAssignedUndefined(); void qtbug_9792(); + void noSpuriousWarningsAtShutdown(); void callQtInvokables(); private: @@ -2238,6 +2239,23 @@ void tst_qdeclarativeecmascript::qtbug_9792() delete object; } +// Test that we shut down without stupid warnings +void tst_qdeclarativeecmascript::noSpuriousWarningsAtShutdown() +{ + QDeclarativeComponent component(&engine, TEST_FILE("noSpuriousWarningsAtShutdown.qml")); + + QObject *o = component.create(); + + transientErrorsMsgCount = 0; + QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler); + + delete o; + + qInstallMsgHandler(old); + + QCOMPARE(transientErrorsMsgCount, 0); +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12