From de28bc00f514c3ee8d8fd3166973c063766e77fd Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 15 Sep 2021 10:12:21 +0200 Subject: QQmlBinding::dependencies: Handle QProperty The method did not consider QProperty properties, as those do not show up via the active guards mechanism. At some point, we probably also want to introduce QQmlAnyBinding::dependencies, as there are now bindings which do not derive from QQmlBinding. Pick-to: 6.2 Change-Id: Ib4b227a440e9494c09d92028f9eaa5ad1e87342f Reviewed-by: Ulf Hermann Reviewed-by: Andrei Golubev --- .../tst_bindingdependencyapi.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/auto/qml/bindingdependencyapi') diff --git a/tests/auto/qml/bindingdependencyapi/tst_bindingdependencyapi.cpp b/tests/auto/qml/bindingdependencyapi/tst_bindingdependencyapi.cpp index dfb595ffb0..81162c2c8a 100644 --- a/tests/auto/qml/bindingdependencyapi/tst_bindingdependencyapi.cpp +++ b/tests/auto/qml/bindingdependencyapi/tst_bindingdependencyapi.cpp @@ -48,6 +48,7 @@ private slots: void testConditionalDependencies_data(); void testConditionalDependencies(); void testBindingLoop(); + void testQproperty(); private: bool findProperties(const QVector &properties, QObject *obj, const QString &propertyName, const QVariant &value); @@ -354,6 +355,36 @@ void tst_bindingdependencyapi::testBindingLoop() delete rect; } +void tst_bindingdependencyapi::testQproperty() +{ + QQmlEngine engine; + QQmlComponent c(&engine); + c.setData(QByteArray("import QtQuick 2.0\n" + "Item {\n" + "id: root\n" + "Text {\n" + "id: label\n" + "text: root.x\n" + "}\n" + "}"), QUrl()); + QScopedPointer root(c.create()); + QVERIFY(!root.isNull()); + QObject *text = root->findChildren().front(); + QVERIFY(text); + auto data = QQmlData::get(text); + QVERIFY(data); + auto b = data->bindings; + QVERIFY(b); + auto binding = dynamic_cast(b); + QVERIFY(binding); + auto dependencies = binding->dependencies(); + QCOMPARE(dependencies.size(), 1); + auto dependency = dependencies.front(); + QVERIFY(dependency.isValid()); + QCOMPARE(quintptr(dependency.object()), quintptr(root.get())); + QCOMPARE(dependency.property().name(), "x"); +} + QTEST_MAIN(tst_bindingdependencyapi) #include "tst_bindingdependencyapi.moc" -- cgit v1.2.3