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 bb698b7f2e)
(cherry picked from commit 20fd12d7f5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ulf Hermann 2023-10-03 19:11:56 +02:00 committed by Qt Cherry-pick Bot
parent b5fae31538
commit 18acf22095
2 changed files with 15 additions and 0 deletions

View File

@ -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)

View File

@ -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());
}