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 commitbb698b7f2e
) (cherry picked from commit20fd12d7f5
) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b5fae31538
commit
18acf22095
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue