From 44ca1085d65d15ffd8cfaf45bb79cc82938e965d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 2 May 2023 18:40:40 +0200 Subject: 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 --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') 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 o(c.create()); + QVERIFY(!o.isNull()); + + QObject *a = o->property("a").value(); + 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()); + QCOMPARE(timeIndex.value(), qsizetype(1)); + + QObject *b = o->property("b").value(); + QVERIFY(b); + QCOMPARE(b->property("z").toInt(), 2); +} + QTEST_MAIN(tst_QmlCppCodegen) #include "tst_qmlcppcodegen.moc" -- cgit v1.2.3