diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-07-26 15:28:44 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-07-28 16:42:45 +0200 |
| commit | fa6aedf7ac7c83ec056271a00cab21bc2516391c (patch) | |
| tree | a59bc996ea3926fd0942d8f9d6862038ff3ec9c9 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | b0b940e472cb47834759fb0eaa486500927eb467 (diff) | |
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
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<QObject> 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; |
