summaryrefslogtreecommitdiff
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-05-02 18:40:40 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-05-04 11:48:09 +0200
commit44ca1085d65d15ffd8cfaf45bb79cc82938e965d (patch)
tree30018ae125053bc91818d5fdbb9543cc76cb69af /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parentb8814dfb364e1316e3ee049d5d7cda9e23537d93 (diff)
downloadqtdeclarative-44ca1085d65d15ffd8cfaf45bb79cc82938e965d.tar.gz
QML: Fix call frame conversion for QVariant return types
The function may return a QVariant in place of the actual type because it cannot express the actual type as-is. This case needs special care because QMetaType::convert() doesn't know what to do with it. Pick-to: 6.5 Fixes: QTBUG-112837 Change-Id: Ibf93a28aa6a60d49c5ab63fa7eed5f5a8e58e163 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 0cad3eb68e..a856d57cfe 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -187,6 +187,7 @@ private slots:
void shadowedMethod();
void topLevelComponent();
void intToEnum();
+ void variantReturn();
};
void tst_QmlCppCodegen::initTestCase()
@@ -3807,6 +3808,31 @@ void tst_QmlCppCodegen::intToEnum()
QCOMPARE(m->property("b").toInt(), 24);
}
+void tst_QmlCppCodegen::variantReturn()
+{
+ QQmlEngine e;
+ QQmlComponent c(&e, QUrl(u"qrc:/qt/qml/TestTypes/variantReturn.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ QObject *a = o->property("a").value<QObject *>();
+ QVERIFY(a);
+ const QVariant x = a->property("x");
+ const QMetaObject *meta = x.metaType().metaObject();
+ QVERIFY(meta);
+ const QMetaProperty property = meta->property(meta->indexOfProperty("timeIndex"));
+ QVERIFY(property.isValid());
+ const QVariant timeIndex = property.readOnGadget(x.data());
+ QCOMPARE(timeIndex.metaType(), QMetaType::fromType<qsizetype>());
+ QCOMPARE(timeIndex.value<qsizetype>(), qsizetype(1));
+
+ QObject *b = o->property("b").value<QObject *>();
+ QVERIFY(b);
+ QCOMPARE(b->property("z").toInt(), 2);
+}
+
QTEST_MAIN(tst_QmlCppCodegen)
#include "tst_qmlcppcodegen.moc"