diff options
5 files changed, 53 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index c29b0fd1f0..265b26b1e0 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -144,7 +144,7 @@ static bool fromMatchingType( // At this point, s should be a builtin type. For builtin types // the QMetaType converters are good enough. if (QMetaType::convert(sourceMetaType, s.constData(), parameterType, parameter.data())) { - callConstructor(mo, i, s.data(), metaType, data); + callConstructor(mo, i, parameter.data(), metaType, data); return true; } } diff --git a/tests/auto/qml/qqmlvaluetypeproviders/data/structuredValueTypes.qml b/tests/auto/qml/qqmlvaluetypeproviders/data/structuredValueTypes.qml index 3101effe96..6a42a4f1a8 100644 --- a/tests/auto/qml/qqmlvaluetypeproviders/data/structuredValueTypes.qml +++ b/tests/auto/qml/qqmlvaluetypeproviders/data/structuredValueTypes.qml @@ -15,6 +15,14 @@ MyTypeObject { property constructible c3 property constructible c4 + property constructibleFromQReal cr1: 11.25 + property constructibleFromQReal cr2: Infinity + property constructibleFromQReal cr3: -Infinity + property constructibleFromQReal cr4: NaN + property constructibleFromQReal cr5: 0 + property constructibleFromQReal cr6: -112.5 + property constructibleFromQReal cr7: 50 + property list<point> ps: [{x: 1, y: 2}, {x: 3, y: 4}, {x: 55, y: Qt.locale("en_AU")}] property list<size> ss: [{width: 5, height: 6}, {width: 7, height: 8}, {height: 99}] property list<constructible> cs: [1, 2, 3, 4, 5, {}] diff --git a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp index b46eebc2e7..1746957872 100644 --- a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp +++ b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.cpp @@ -6,5 +6,6 @@ void registerTypes() { qmlRegisterType<MyTypeObject>("Test", 1, 0, "MyTypeObject"); qmlRegisterTypesAndRevisions<ConstructibleValueType>("Test", 1); + qmlRegisterTypesAndRevisions<ConstructibleFromQReal>("Test", 1); qmlRegisterTypesAndRevisions<StructuredValueType>("Test", 1); } diff --git a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h index 0fc0fd7840..263d77bd4d 100644 --- a/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h +++ b/tests/auto/qml/qqmlvaluetypeproviders/testtypes.h @@ -42,6 +42,33 @@ private: int m_foo = 0; }; +struct ConstructibleFromQReal +{ + Q_GADGET + Q_PROPERTY(qreal foo MEMBER m_foo CONSTANT) + + QML_VALUE_TYPE(constructibleFromQReal) + QML_CONSTRUCTIBLE_VALUE + +public: + ConstructibleFromQReal() = default; + Q_INVOKABLE ConstructibleFromQReal(qreal foo) : m_foo(foo) {} + + qreal foo() const { return m_foo; } + +private: + friend bool operator==(const ConstructibleFromQReal &a, const ConstructibleFromQReal &b) + { + if (qIsNaN(a.m_foo) && qIsNaN(b.m_foo)) + return true; + if (qIsInf(a.m_foo) && qIsInf(b.m_foo)) + return (a.m_foo > 0) == (b.m_foo > 0); + return qFuzzyCompare(a.m_foo, b.m_foo); + } + + qreal m_foo = 0; +}; + struct StructuredValueType { Q_GADGET diff --git a/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp index 230c9e09e7..163fcd6336 100644 --- a/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp +++ b/tests/auto/qml/qqmlvaluetypeproviders/tst_qqmlvaluetypeproviders.cpp @@ -268,7 +268,7 @@ void tst_qqmlvaluetypeproviders::structured() QTest::ignoreMessage(QtWarningMsg, warning); QTest::ignoreMessage(QtWarningMsg, qPrintable( - url.toString() + QStringLiteral(":36: Error: Cannot assign QJSValue " + url.toString() + QStringLiteral(":44: Error: Cannot assign QJSValue " "to ConstructibleValueType"))); QTest::ignoreMessage(QtWarningMsg, qPrintable( @@ -327,6 +327,21 @@ void tst_qqmlvaluetypeproviders::structured() structured.setC(12); structured.setP(QPointF(7, 8)); QCOMPARE(t->structured(), structured); + + QCOMPARE(o->property("cr1").value<ConstructibleFromQReal>(), + ConstructibleFromQReal(11.25)); + QCOMPARE(o->property("cr2").value<ConstructibleFromQReal>(), + ConstructibleFromQReal(std::numeric_limits<qreal>::infinity())); + QCOMPARE(o->property("cr3").value<ConstructibleFromQReal>(), + ConstructibleFromQReal(-std::numeric_limits<qreal>::infinity())); + QCOMPARE(o->property("cr4").value<ConstructibleFromQReal>(), + ConstructibleFromQReal(std::numeric_limits<qreal>::quiet_NaN())); + QCOMPARE(o->property("cr5").value<ConstructibleFromQReal>(), + ConstructibleFromQReal(0)); + QCOMPARE(o->property("cr6").value<ConstructibleFromQReal>(), + ConstructibleFromQReal(-112.5)); + QCOMPARE(o->property("cr7").value<ConstructibleFromQReal>(), + ConstructibleFromQReal(50)); } void tst_qqmlvaluetypeproviders::recursive() |