diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-01-03 13:48:50 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-01-06 17:27:59 +0100 |
| commit | 0f0f0adc515755aa9d4576842e1ea9bca3928a6c (patch) | |
| tree | 197b644dad31a95f18d471853793452759aa1b39 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | 78ccc84dde92d787a08b7cab6486527e9e57f183 (diff) | |
QtQml: Check 'this' for null in callObjectPropertyLookup
Before the refactoring of callObjectPropertyLookup and
initCallObjectPropertyLookup this was done via a check on the resulting
function. This check is in the init method now. However, after
initialization, you can still call the (pre-resolved) method on a nullptr.
Therefore, we need a second check.
The method counts as pre-resolved even if we re-fetch it due to a
variant lookup. We can be sure that there is some method in that case
after all.
Amends commit a741271dd58b21728928684f1ef1efaa91e79ebf
Pick-to: 6.9
Fixes: QTBUG-132499
Change-Id: Idb8c50f3698c5502cf2e8116e6341ef1a537bc64
Reviewed-by: Olivier De Cannière <olivier.decanniere@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 0fd90e90fd..4217206307 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -64,6 +64,7 @@ private slots: void brokenAs(); void boundComponents(); void callContextPropertyLookupResult(); + void callObjectLookupOnNull(); void callWithSpread(); void colorAsVariant(); void colorString(); @@ -1021,6 +1022,25 @@ void tst_QmlCppCodegen::callContextPropertyLookupResult() QVERIFY(qvariant_cast<QQmlComponent *>(o->property("c")) != nullptr); } +void tst_QmlCppCodegen::callObjectLookupOnNull() +{ + QQmlEngine engine; + const QString urlString = u"qrc:/qt/qml/TestTypes/callObjectLookupOnNull.qml"_s; + QQmlComponent c(&engine, QUrl(urlString)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + + QCOMPARE(o->objectName(), u"horst"_s); + + QTest::ignoreMessage( + QtWarningMsg, + qPrintable(urlString + u":5:5: TypeError: Cannot call method 'getName' of null")); + o->setProperty("person", QVariant::fromValue<Person *>(nullptr)); + + QCOMPARE(o->objectName(), QString()); +} + void tst_QmlCppCodegen::callWithSpread() { QQmlEngine engine; |
