aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-08-07 16:42:22 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-09-02 09:15:10 +0200
commitb1c48db754c7019e0472d0baf6d71d2bd93a205b (patch)
tree59d174c30931ab8a95bc513d840553e182cc4f07 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent2d016a2653c59f10a57dc1903b817f71d16d0622 (diff)
QmlCompiler: Ensure QObjects returned to AOT-compiled code are wrapped
If a QObject is returned from a method call, the QML engine takes ownership of it and it needs to be deleted by the garbage collector. Our generated C++ code so far did not actually take ownership of the object and thereby caused it to leak. Pick-to: 6.10 6.9 6.8 Fixes: QTBUG-138919 Change-Id: I7bd57b3612bf4b98937756e8a7a7c03aff1c9b32 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.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 243b6b1296..406bcb1da8 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -70,6 +70,7 @@ private slots:
void brokenAs();
void boundComponents();
void callContextPropertyLookupResult();
+ void callFactoryFunction();
void callObjectLookupOnNull();
void callWithSpread();
void collectGarbageDuringAotCode();
@@ -1072,6 +1073,19 @@ void tst_QmlCppCodegen::callContextPropertyLookupResult()
QVERIFY(qvariant_cast<QQmlComponent *>(o->property("c")) != nullptr);
}
+void tst_QmlCppCodegen::callFactoryFunction()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/callFactory.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+
+ QTest::ignoreMessage(QtDebugMsg, "Object created: 0");
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+
+ QTest::ignoreMessage(QtDebugMsg, "Object destroyed: 0");
+}
+
void tst_QmlCppCodegen::callObjectLookupOnNull()
{
QQmlEngine engine;