aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/callFactory.qml10
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/cppobj.h46
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp14
4 files changed, 72 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 4b5dd31c0a..c0da4370fc 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -10,6 +10,7 @@ set(cpp_sources
collector.h
convertQJSPrimitiveValueToIntegral.h
cppbaseclass.h
+ cppobj.h
detachedreferences.h
druggeljug.h
dummyobjekt.h
@@ -116,6 +117,7 @@ set(qml_files
brokenAs.qml
boundComponents.qml
callContextPropertyLookupResult.qml
+ callFactory.qml
callObjectLookupOnNull.qml
callWithSpread.qml
childobject.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/callFactory.qml b/tests/auto/qml/qmlcppcodegen/data/callFactory.qml
new file mode 100644
index 0000000000..1b5d9eaec8
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/callFactory.qml
@@ -0,0 +1,10 @@
+pragma Strict
+import QtQml
+import TestTypes
+
+QtObject {
+ Component.onCompleted: {
+ // Call the factory function and then forget the object
+ const orphanedObj = CppBridge.singleObj(0)
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/data/cppobj.h b/tests/auto/qml/qmlcppcodegen/data/cppobj.h
new file mode 100644
index 0000000000..3b64c21e74
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/cppobj.h
@@ -0,0 +1,46 @@
+// Copyright (C) 2025 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef CPPOBJ_H
+#define CPPOBJ_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qdebug.h>
+#include <QtQmlIntegration/qqmlintegration.h>
+
+class CppObj : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ Q_PROPERTY(int identifier MEMBER m_identifier CONSTANT)
+
+public:
+ explicit CppObj(int identifier = -1, QObject *parent = nullptr)
+ : QObject(parent)
+ , m_identifier(identifier)
+ {
+ qDebug() << "Object created:" << m_identifier;
+ }
+
+ ~CppObj() { qDebug() << "Object destroyed:" << m_identifier; }
+
+private:
+ int m_identifier = -1;
+};
+
+class CppBridge : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
+public:
+ explicit CppBridge(QObject *parent = nullptr) : QObject{parent} {}
+
+ Q_INVOKABLE CppObj *singleObj(int identifier) const
+ {
+ return new CppObj(identifier);
+ }
+};
+
+#endif // CPPOBJ_H
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;