diff options
author | Alex Montgomery <apmontgomery@gmail.com> | 2014-08-15 09:41:56 -0700 |
---|---|---|
committer | Alex Montgomery <apmontgo@codereview.qt-project.org> | 2014-08-15 18:48:33 +0200 |
commit | 672c533bde2899baad3eb29b6a807870abb8bf25 (patch) | |
tree | 8e8838f7c5ecd807cfb666f1dd13bf363ef3ae88 | |
parent | 63f0c196eecb88804f8bbe410a38d0274955f994 (diff) |
Fix setContextObject to re-evaluate bindings
Fix QQmlContext::setContextObject to reevaluate bindings as the
documentation says that it should.
Task-number: QTBUG-40798
Change-Id: Ifbd97c7a07a5432f4948937da863370b05705206
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index 7b1ba46db2..0a550f5d0b 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -280,6 +280,7 @@ void QQmlContext::setContextObject(QObject *object) } data->contextObject = object; + data->refreshExpressions(); } /*! diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index 147887109f..e9c031a894 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -401,6 +401,18 @@ void tst_qqmlcontext::setContextObject() delete obj; } + + // Change of context object + ctxt.setContextProperty("c", QVariant(30)); + TestObject to2; + to2.setA(10); + to2.setB(20); + to2.setC(40); + ctxt.setContextObject(&to2); + + TEST_CONTEXT_PROPERTY(&ctxt, a, QVariant(10)); + TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(20)); + TEST_CONTEXT_PROPERTY(&ctxt, c, QVariant(30)); } void tst_qqmlcontext::destruction() |