diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-04-15 19:13:05 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-04-16 14:29:55 +0200 |
commit | 9cd1e7902ce882a54e369556068f2707090df658 (patch) | |
tree | c581708059b88ea22726983fe06c7b3ab3886001 /tests/auto/qml/qqmlcontext | |
parent | 7fc9e671077a09294a62b160a4aa0fb006192956 (diff) |
Fix QQmlContext::nameForObject()
nameForObject() should not search the linked contexts. Linked contexts
are not reachable from the "head" context in QML. However, it should
search context objects, just like contextProperty() does.
[ChangeLog][QtQml][Important Behavior Changes]
QQmlContext::nameForObject() now finds properties of context objects,
but it does not search unrelated other ("linked") contexts anymore.
Change-Id: Ic6e01fddf3e2d4b3a1bc7308e126f47fae7cd6d1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlcontext')
-rw-r--r-- | tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index 9635972f7f..4a850541a6 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -595,6 +595,10 @@ void tst_qqmlcontext::objectsAndNames() QObject *containmentMask = qvariant_cast<QObject *>(ctxtObj->property("containmentMask")); QCOMPARE(containmentMask->objectName(), QStringLiteral("ddd")); + QCOMPARE(extraContext->nameForObject(aa), QStringLiteral("aa")); + QCOMPARE(extraContext->nameForObject(bb), QStringLiteral("bb")); + QCOMPARE(extraContext->nameForObject(cc), QStringLiteral("cc")); + QCOMPARE(extraContext->nameForObject(containmentMask), QStringLiteral("containmentMask")); QCOMPARE(extraContext->objectForName(QStringLiteral("aa")), aa); QCOMPARE(extraContext->objectForName(QStringLiteral("bb")), bb); QCOMPARE(extraContext->objectForName(QStringLiteral("cc")), cc); @@ -612,6 +616,8 @@ void tst_qqmlcontext::objectsAndNames() // objectForName and nameForObject deliberately don't QCOMPARE(extraContext->objectForName(QStringLiteral("root")), nullptr); QCOMPARE(extraContext->objectForName(QStringLiteral("nested")), nullptr); + QCOMPARE(extraContext->nameForObject(o.data()), QString()); + QCOMPARE(extraContext->nameForObject(qvariant_cast<QObject*>(o->property("o"))), QString()); } class DeleteCommand : public QObject |