diff options
| -rw-r--r-- | src/qml/qml/qqmlbinding_p.h | 8 | ||||
| -rw-r--r-- | src/quick/util/qquickstategroup.cpp | 9 | ||||
| -rw-r--r-- | tests/auto/quick/qquickstates/data/jsValueWhen2.qml | 20 | ||||
| -rw-r--r-- | tests/auto/quick/qquickstates/tst_qquickstates.cpp | 12 |
4 files changed, 39 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h index 08e61a7aef..00aa0d6f58 100644 --- a/src/qml/qml/qqmlbinding_p.h +++ b/src/qml/qml/qqmlbinding_p.h @@ -79,6 +79,10 @@ public: }; QVariant evaluate(); + bool evaluate(void *result, QMetaType type) + { + return QQmlJavaScriptExpression::evaluate(&result, &type, 0); + } void expressionChanged() override; @@ -116,10 +120,6 @@ protected: QQmlPropertyData::WriteFlags flags); QV4::ReturnedValue evaluate(bool *isUndefined); - bool evaluate(void *result, QMetaType type) - { - return QQmlJavaScriptExpression::evaluate(&result, &type, 0); - } private: static QQmlBinding *newBinding(const QQmlPropertyData *property); diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp index 68caa6590d..b4be946dc3 100644 --- a/src/quick/util/qquickstategroup.cpp +++ b/src/quick/util/qquickstategroup.cpp @@ -353,11 +353,10 @@ bool QQuickStateGroupPrivate::updateAutoState() if (abstractBinding && abstractBinding->kind() == QQmlAbstractBinding::QmlBinding) { QQmlBinding *binding = static_cast<QQmlBinding *>(abstractBinding); if (binding->hasValidContext()) { - QVariant evalResult = binding->evaluate(); - if (evalResult.metaType() == QMetaType::fromType<QJSValue>()) - whenValue = evalResult.value<QJSValue>().toBool(); - else - whenValue = evalResult.toBool(); + const auto boolType = QMetaType::fromType<bool>(); + const bool isUndefined = !binding->evaluate(&whenValue, boolType); + if (isUndefined) + whenValue = false; } } diff --git a/tests/auto/quick/qquickstates/data/jsValueWhen2.qml b/tests/auto/quick/qquickstates/data/jsValueWhen2.qml new file mode 100644 index 0000000000..e1f173138e --- /dev/null +++ b/tests/auto/quick/qquickstates/data/jsValueWhen2.qml @@ -0,0 +1,20 @@ +import QtQuick 2.15 + +Item { + id: root + property var prop: null + property bool works: false + states: [ + State { + name: "mystate" + when: root.prop + PropertyChanges { + target: root + works: "works" + } + } + ] + Component.onCompleted: root.prop = Qt.createQmlObject( + "import QtQml 2.15\nQtObject {}", + root, "dynamicSnippet") +} diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 62fca7d280..44187d2b65 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -175,6 +175,7 @@ private slots: void revertListMemoryLeak(); void duplicateStateName(); void trivialWhen(); + void jsValueWhen_data(); void jsValueWhen(); void noStateOsciallation(); void parentChangeCorrectReversal(); @@ -1695,11 +1696,20 @@ void tst_qquickstates::trivialWhen() QVERIFY(root); } + +void tst_qquickstates::jsValueWhen_data() +{ + QTest::addColumn<QByteArray>("fileName"); + QTest::addRow("jsObject") << QByteArray("jsValueWhen.qml"); + QTest::addRow("qmlObject") << QByteArray("jsValueWhen2.qml"); +} + void tst_qquickstates::jsValueWhen() { + QFETCH(QByteArray, fileName); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("jsValueWhen.qml")); + QQmlComponent c(&engine, testFileUrl(fileName.constData())); QScopedPointer<QObject> root(c.create()); QVERIFY(root); QVERIFY(root->property("works").toBool()); |
