aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-10-08 08:15:30 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-10-09 09:24:59 +0200
commit4381eaf567337c2b2892adeec0d2fef878c1eed3 (patch)
tree332556928f35f84caa12e8815e39838c916724dd /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parentb689344574c649ea96afc168a5c8767668bfb35c (diff)
QtQml: Reset scope object call lookup if it fails
In exceptional circumstances the function can turn out to be null. This may happen if the context has already been torn down. We must not try to call it then. Also, fix the error message to include the actual object. Pick-to: 6.10 Fixes: QTBUG-140465 Change-Id: I6fc446fbc8df70c9652c1efef03daed9fa9ea839 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 9bbe15ca7d..86e6c4cd16 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -98,6 +98,7 @@ private slots:
void cppValueTypeList();
void dateConstruction();
void dateConversions();
+ void deadContext();
void deadShoeSize();
void deduplicateConversionOrigins();
void destroyAndToString();
@@ -1673,6 +1674,28 @@ void tst_QmlCppCodegen::dateConversions()
}
+void tst_QmlCppCodegen::deadContext()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/deadContext.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+
+ const char *vmeError = "QQmlVMEMetaObject: Internal error "
+ "- attempted to evaluate a function in an invalid context";
+ static const QRegularExpression timerError(
+ u"qrc:/qt/qml/TestTypes/deadContext\\.qml:[0-9]+: TypeError: Property 'doit' of "
+ "object QQmlTimer_QML_[0-9]+\\(0x[0-9a-f]+\\) is not a function"_s);
+
+ for (int i = 0; i < 4; ++i) {
+ QTest::ignoreMessage(QtWarningMsg, vmeError);
+ QTest::ignoreMessage(QtWarningMsg, timerError);
+ }
+
+ QTRY_COMPARE(o->property("choice").toInt(), 4);
+}
+
void tst_QmlCppCodegen::deadShoeSize()
{
QQmlEngine engine;