QtScript: Passing an array of objects to C++
- by Plow
Hi,
I want to pass an array of objects from my QtScript to C++ but I have not been able to figure out how to achieve this. As soon as I create an array, the elements inside it are converted to strings before I can access them.
This is what I have been trying so far:
class myObject : public QObject, public QScriptable
{
Q_OBJECT
public Q_SLOTS:
void test(QVariantList list);
};
void myObject::test(QVariantList list)
{
for (QVariantList::const_iterator it = list.begin(); it != list.end(); ++it) {
QVariant element = *it;
qDebug() << "List element type: " << element.typeName();
if (element.canConvert<QVariantMap>()) {
// Not getting here
}
}
}
The following script
myObject.test([{"foo": 1, "bar": 2}, {"baaz": 3, "baaaz": 4}]);
prints
List element type: "QString"
List element type: "QString"
I am using Qt 4.6...