aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-09-03 14:35:26 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-09-06 18:31:11 +0200
commitdbcc2e7d56fca7cfe9209d1cb5b0640a0d3203d0 (patch)
tree0a573cce94df71b5bcbb13037849cd3a924a1322 /tests/auto
parentbfe3e183d5817a09f04fc58b0b9ac59341111755 (diff)
Use value type providers in metaTypeFromJS
Task-number: QTBUG-96144 Change-Id: If12f669ae33bb8ae4768ca79e4ca985f70a2651d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 9d9df8073dcee685ce47074e93022e3e2b75b2b8)
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qqmlengine/tst_qqmlengine.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
index e1dff63e03..e74be6929c 100644
--- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
+++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
@@ -91,6 +91,7 @@ private slots:
void listWrapperAsListReference();
void attachedObjectAsObject();
void listPropertyAsQJSValue();
+ void stringToColor();
public slots:
QObject *createAQObjectForOwnershipTest ()
@@ -1410,6 +1411,31 @@ void tst_qqmlengine::listPropertyAsQJSValue()
QCOMPARE(prop.at(&prop, 0), &c);
}
+void tst_qqmlengine::stringToColor()
+{
+ QQmlEngine engine;
+
+ // Make it import QtQuick, so that color becomes available.
+ QQmlComponent c(&engine);
+ c.setData("import QtQuick\nItem {}", QUrl());
+ QVERIFY(c.isReady());
+ QScopedPointer<QObject> o(c.create());
+
+ const QMetaType metaType(QMetaType::QColor);
+ QVariant color(metaType);
+ QVERIFY(engine.handle()->metaTypeFromJS(
+ engine.handle()->newString(QStringLiteral("#abcdef"))->asReturnedValue(),
+ metaType, color.data()));
+ QVERIFY(color.isValid());
+ QCOMPARE(color.metaType(), metaType);
+
+ QVariant variant(QStringLiteral("#abcdef"));
+ QVERIFY(variant.convert(metaType));
+ QCOMPARE(variant.metaType(), metaType);
+
+ QCOMPARE(color, variant);
+}
+
QTEST_MAIN(tst_qqmlengine)
#include "tst_qqmlengine.moc"