aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp16
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/ValueTypeArgument.qml21
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/largeValueType.h15
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp13
5 files changed, 64 insertions, 3 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index 9b69a2f3cf..67aa2a5c1f 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -238,9 +238,19 @@ QT_WARNING_POP
result.code += registerIt->variableName + u" = "_s;
- const QString originalValue
- = u"(*static_cast<"_s + castTargetName(originalArgument.storedType())
- + u"*>(argv["_s + QString::number(argumentIndex + 1) + u"]))"_s;
+ const auto originalContained = m_typeResolver->originalContainedType(argument);
+ QString originalValue;
+ const bool needsQVariantWrapping = !m_typeResolver->globalType(storedType).isList()
+ && !originalContained->isReferenceType()
+ && m_typeResolver->equals(storedType, m_typeResolver->varType())
+ && !m_typeResolver->equals(originalContained, m_typeResolver->varType());
+ if (needsQVariantWrapping) {
+ originalValue = u"QVariant(%1, argv[%2])"_s.arg(metaTypeFromName(originalContained))
+ .arg(QString::number(argumentIndex + 1));
+ } else {
+ originalValue = u"(*static_cast<"_s + castTargetName(originalArgument.storedType())
+ + u"*>(argv["_s + QString::number(argumentIndex + 1) + u"]))"_s;
+ }
if (needsConversion)
result.code += conversion(originalArgument, argument, originalValue);
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 889edbe0a6..4a113fb964 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -14,6 +14,7 @@ set(cpp_sources
getOptionalLookup.h
gadgetwithenum.h
invisible.h
+ largeValueType.h
listprovider.h
multiforeign.h
objectwithmethod.h
@@ -73,6 +74,7 @@ set(qml_files
StoreMetaEnum.qml
Test.qml
TestCase.qml
+ ValueTypeArgument.qml
Variable.qml
WindowDerived.qml
aliasLookup.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/ValueTypeArgument.qml b/tests/auto/qml/qmlcppcodegen/data/ValueTypeArgument.qml
new file mode 100644
index 0000000000..5da1b253e0
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/ValueTypeArgument.qml
@@ -0,0 +1,21 @@
+pragma Strict
+
+import QtQml
+import TestTypes
+
+QtObject {
+ id: root
+ property largeValueType l
+
+ function callee(l: largeValueType) : void {
+ console.log("Reading l.i=" + l.i)
+ }
+
+ function caller() : void {
+ callee(root.l)
+ }
+
+ Component.onCompleted: {
+ caller()
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/data/largeValueType.h b/tests/auto/qml/qmlcppcodegen/data/largeValueType.h
new file mode 100644
index 0000000000..028a5f690f
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/largeValueType.h
@@ -0,0 +1,15 @@
+#include <qqmlintegration.h>
+#include <qqml.h>
+
+class LargeValueType
+{
+ Q_GADGET
+ QML_VALUE_TYPE(largeValueType)
+ Q_PROPERTY(int i READ i)
+
+private:
+ int i() const { return m_i; }
+
+ char m_probablyDefinitelyBiggerThanQVariantInlineStorage[2048]{};
+ int m_i = 5;
+};
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 5505e30e3b..e5e30e0210 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -248,6 +248,7 @@ private slots:
void unstoredUndefined();
void unusedAttached();
void urlString();
+ void valueTypeArgument();
void valueTypeBehavior();
void valueTypeLists();
void valueTypeProperty();
@@ -4956,6 +4957,18 @@ void tst_QmlCppCodegen::urlString()
QCOMPARE(rootObject->objectName(), QLatin1String("http://dddddd.com"));
}
+void tst_QmlCppCodegen::valueTypeArgument()
+{
+ QTest::ignoreMessage(QtMsgType::QtDebugMsg, "Reading l.i=5");
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/ValueTypeArgument.qml"_s));
+
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> rootObject(component.create());
+ QVERIFY(rootObject);
+}
+
void tst_QmlCppCodegen::valueTypeBehavior()
{
QQmlEngine engine;