From f17b826a72d77379288aa84a933b9231c279cbad Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 22 Sep 2017 15:01:27 +0200 Subject: Fix behaviors not working when sub-types declare properties Since commit 81867dfbf9c16d4300727a08eed9b5c6c979e0ba we have an optimization in place to avoid the virtual meta-call when writing properties that cannot be intercepted. Unfortunately that check did not take parent VME meta-objects into account, which triggered the bug. Test case by Harald Hvaal Task-number: QTBUG-63365 Change-Id: I66cb2967da2c09ca5e38cebd9db2ee6e3ee78f5f Reviewed-by: Erik Verbruggen --- src/qml/qml/qqmlvmemetaobject_p.h | 2 ++ .../quick/qquickbehaviors/data/ItemWithInnerBehavior.qml | 10 ++++++++++ .../quick/qquickbehaviors/data/overwrittenbehavior.qml | 14 ++++++++++++++ tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp | 9 +++++++++ 4 files changed, 35 insertions(+) create mode 100644 tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml create mode 100644 tests/auto/quick/qquickbehaviors/data/overwrittenbehavior.qml diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index ede1dd74f9..2dff2b7a01 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -112,6 +112,8 @@ public: if (it->m_propertyIndex == propertyIndex) return true; } + if (auto parentInterceptor = ((parent.isT1() && parent.flag()) ? static_cast(parent.asT1()) : 0)) + return parentInterceptor->intercepts(propertyIndex); return false; } diff --git a/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml b/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml new file mode 100644 index 0000000000..09983645ef --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml @@ -0,0 +1,10 @@ +import QtQuick 2.4 + +Item { + id: root + + property bool someValue + Behavior on someValue { + ScriptAction { script: { parent.behaviorTriggered = true }} + } +} diff --git a/tests/auto/quick/qquickbehaviors/data/overwrittenbehavior.qml b/tests/auto/quick/qquickbehaviors/data/overwrittenbehavior.qml new file mode 100644 index 0000000000..e627c45782 --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/overwrittenbehavior.qml @@ -0,0 +1,14 @@ +import QtQuick 2.4 + +Item { + property bool behaviorTriggered + property bool someProperty + + ItemWithInnerBehavior { + //the existence of this property triggers the bug + property bool iDoAbsolutelyNothing + + Component.onCompleted: parent.someProperty = true + someValue: parent.someProperty + } +} diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index 80c76a377b..bdd53702e5 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -72,6 +72,7 @@ private slots: void currentValue(); void disabledWriteWhileRunning(); void aliasedProperty(); + void innerBehaviorOverwritten(); }; void tst_qquickbehaviors::simpleBehavior() @@ -589,6 +590,14 @@ void tst_qquickbehaviors::aliasedProperty() //i.e. the behavior has been triggered } +void tst_qquickbehaviors::innerBehaviorOverwritten() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("overwrittenbehavior.qml")); + QScopedPointer item(qobject_cast(c.create())); + QVERIFY(item->property("behaviorTriggered").toBool()); +} + QTEST_MAIN(tst_qquickbehaviors) #include "tst_qquickbehaviors.moc" -- cgit v1.2.3