From fa6aedf7ac7c83ec056271a00cab21bc2516391c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 26 Jul 2023 15:28:44 +0200 Subject: QmlCompiler: Allow calling methods on potentially undefined QObjects We can use the same technique as for GetLookup there. Just check the variant for validity to see if we can call it. Change-Id: I1bcf4a5a84f47e0236762827488bc5d03e015efb Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 674bfdef5d..0c9648a19d 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -133,6 +133,7 @@ private slots: void mathMinMax(); void mathOperations(); void mergedObjectReadWrite(); + void methodOnListLookup(); void methods(); void modulePrefix(); void multiForeign(); @@ -2666,6 +2667,25 @@ void tst_QmlCppCodegen::mergedObjectReadWrite() } } +void tst_QmlCppCodegen::methodOnListLookup() +{ + QQmlEngine engine; + const QUrl url(u"qrc:/qt/qml/TestTypes/methodOnListLookup.qml"_s); + QQmlComponent component(&engine, url); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + + QScopedPointer o(component.create()); + QVERIFY(!o.isNull()); + + QCOMPARE(o->objectName(), u"no one"); + + QTest::ignoreMessage( + QtWarningMsg, + qPrintable(url.toString() + + ":14: TypeError: Cannot call method 'getName' of undefined"_L1)); + QMetaObject::invokeMethod(o.data(), "boom"); +} + void tst_QmlCppCodegen::methods() { QQmlEngine engine; -- cgit v1.2.3