diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-05-11 13:16:10 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-05-19 09:21:00 +0200 |
commit | d911034f461859a72b45aeca0f34c34808e3f09b (patch) | |
tree | cbe6ec5a93c7efd95ca71dfefe6c91f517100b89 /tests/auto/qml/qqmllanguage | |
parent | 3c1e3552d301e064cf8b9380c4c6f5564f797ec4 (diff) |
QV4Engine: Fix type conversion
When converting JS arrays to sequence<T> type, check first for the
existence of a QJSValue -> T converter function. This restores the
behavior from Qt <= 5.14. Amends ecdb4ed275a0869dc668d73d774735575d43a0a3
Fixes: QTBUG-84104
Change-Id: I14c86ab37e34a3c8cff072574d4b90fe9e558535
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/arrayToContainer.qml | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 26 |
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/arrayToContainer.qml b/tests/auto/qml/qqmllanguage/data/arrayToContainer.qml index d8e278a7a1..bc1b0d51e0 100644 --- a/tests/auto/qml/qqmllanguage/data/arrayToContainer.qml +++ b/tests/auto/qml/qqmllanguage/data/arrayToContainer.qml @@ -6,4 +6,5 @@ TestItem { property var myset positions: vector barrays: myset + convertibles: ["hello", "world"] } diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index b4888f6fa7..77e545722a 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -5775,23 +5775,47 @@ void tst_qqmllanguage::inlineComponentDuplicateNameError() QCOMPARE(component.errorString(), message); } +struct QJSValueConvertible { + + Q_GADGET + +public: + QString msg; +}; + +bool operator==(const QJSValueConvertible &lhs, const QJSValueConvertible &rhs) { + return lhs.msg == rhs.msg; +} + class TestItem : public QObject { Q_OBJECT Q_PROPERTY( QVector<QPointF> positions MEMBER m_points ) Q_PROPERTY( QSet<QByteArray> barrays MEMBER m_barrays ) + Q_PROPERTY( QVector<QJSValueConvertible> convertibles MEMBER m_convertibles) public: TestItem() = default; QVector< QPointF > m_points; QSet<QByteArray> m_barrays; + QVector<QJSValueConvertible> m_convertibles; }; Q_DECLARE_METATYPE(QVector<QPointF>); Q_DECLARE_METATYPE(QSet<QByteArray>); +Q_DECLARE_METATYPE(QJSValueConvertible); +Q_DECLARE_METATYPE(QVector<QJSValueConvertible>); + void tst_qqmllanguage::arrayToContainer() { + QMetaType::registerConverter< QJSValue, QJSValueConvertible >( + + [](const QJSValue& value) + { + return QJSValueConvertible{value.toString()}; + } + ); QQmlEngine engine; qmlRegisterType<TestItem>("qt.test", 1, 0, "TestItem"); QVector<QPointF> points { QPointF (2.0, 3.0) }; @@ -5804,6 +5828,8 @@ void tst_qqmllanguage::arrayToContainer() QCOMPARE(root->m_points.at(0), QPointF (2.0, 3.0) ); QVERIFY(root->m_barrays.contains("hello")); QVERIFY(root->m_barrays.contains("world")); + QCOMPARE(root->m_convertibles.at(0).msg, QLatin1String("hello")); + QCOMPARE(root->m_convertibles.at(1).msg, QLatin1String("world")); } class EnumTester : public QObject |