From dbcc2e7d56fca7cfe9209d1cb5b0640a0d3203d0 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 3 Sep 2021 14:35:26 +0200 Subject: Use value type providers in metaTypeFromJS Task-number: QTBUG-96144 Change-Id: If12f669ae33bb8ae4768ca79e4ca985f70a2651d Reviewed-by: Fabian Kosmale (cherry picked from commit 9d9df8073dcee685ce47074e93022e3e2b75b2b8) --- tests/auto/qml/qqmlengine/tst_qqmlengine.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/auto') 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 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" -- cgit v1.2.3