aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-05-11 13:16:10 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2020-05-19 09:21:00 +0200
commitd911034f461859a72b45aeca0f34c34808e3f09b (patch)
treecbe6ec5a93c7efd95ca71dfefe6c91f517100b89 /tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
parent3c1e3552d301e064cf8b9380c4c6f5564f797ec4 (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/tst_qqmllanguage.cpp')
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp26
1 files changed, 26 insertions, 0 deletions
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