Details
Description
calling a C++ function from a script with an object containing object members results in the object member being converted to a QString instead of a QVariantMap as documented and as the embedding object has been converted to.
code snippet (excerpt):
— script —
var obj = { foo1: "bar", foo2:
};
globalObject.func(obj);
— c++ —
void MyObject::func(QVariantMap obj) {
qDebug() << obj.value("foo1").toString() << obj.value("foo2").value<QVariantMap>();
}
possible solution: convert the QScriptValue recursively like this:
QVariantMap convertScriptObject(const QScriptValue& object) {
QVariantMap result;
QScriptValueIterator it(object);
if (object.isObject()) {
while (it.hasNext()) {
it.next();
if (it.value().isObject())
else
{ result.insert(it.name(), it.value().toVariant()); } }
}
return result;
}
OR
fixe QScriptValue.toVariant() for this case
Attachments
Issue Links
- relates to
-
QTBUG-3511 Default conversion between QVariant and QtScript Object
- Closed