diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-10-03 19:11:56 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-10-18 12:12:21 +0000 |
commit | 77d28017c4331a2f0dafe4b7dfe7519e19f2929e (patch) | |
tree | fa9df84c0430800d135c53ca9b56fa2398325358 | |
parent | 4cc830764553fc78b1e848a62d066caed973fae4 (diff) |
QtQml: Correctly convert to QQmlListProperty<QObject>
If we have a QQmlListWrapper, we can extract its property.
Fixes: QTBUG-117829
Pick-to: 6.2
Change-Id: I46ae8db1aabf7c1b617a22f371ce4f060cf4bb38
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit bb698b7f2e974a23b688dd15393f6a550448a5a8)
(cherry picked from commit 20fd12d7f569f8a4a6dfc6c7f0d5f270f4683e90)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 0ef2b5db40..c9d8639816 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -2649,6 +2649,13 @@ bool ExecutionEngine::metaTypeFromJS(const Value &value, QMetaType metaType, voi } } + if (metaType == QMetaType::fromType<QQmlListProperty<QObject>>()) { + if (const QV4::QmlListWrapper *wrapper = value.as<QV4::QmlListWrapper>()) { + *reinterpret_cast<QQmlListProperty<QObject> *>(data) = wrapper->d()->property(); + return true; + } + } + if (const QQmlValueTypeWrapper *vtw = value.as<QQmlValueTypeWrapper>()) { const QMetaType valueType = vtw->type(); if (valueType == metaType) diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index c7ed1cf4ef..f08a3dbcaf 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -17,6 +17,7 @@ #include <QScopeGuard> #include <QUrl> #include <QModelIndex> +#include <QtQml/qqmllist.h> #ifdef Q_CC_MSVC #define NO_INLINE __declspec(noinline) @@ -1703,6 +1704,13 @@ void tst_QJSEngine::valueConversion_basic() QCOMPARE(eng.fromScriptValue<QChar>(eng.toScriptValue(c)), c); } + { + QList<QObject *> list = {this}; + QQmlListProperty<QObject> prop(this, &list); + QJSValue jsVal = eng.toScriptValue(prop); + QCOMPARE(eng.fromScriptValue<QQmlListProperty<QObject>>(jsVal), prop); + } + QVERIFY(eng.toScriptValue(static_cast<void *>(nullptr)).isNull()); } |