How to fetch listtype data from qml to cpp?
-
In below program I have used QmlComponent and QMetaObject::invokeMethod its getting for single value but for list it showing error:"ASSERT failure in QList<T>::operator[]: "index out of range"
Here My code:main.cpp
QQmlEngine engine;
QQmlComponent component(&engine,QUrl(QStringLiteral("qrc:/MyItem.qml")));
QObject *object = component.create();
QVariant returnedValue;
QMetaObject::invokeMethod(object, "names",
Q_RETURN_ARG(QVariant, returnedValue));
qDebug() << "QML function returned:" << returnedValue.toString();
delete object;main.qml
Item {
property string name: "apple"
property string two: "banana"
property string three: "mango"
property string one: "lemon"
property string four: "watermelon"
property string five: "pineapple"
property var list: [name,two,three,one,five,four]
function names()
{
console.log("names function");
var arr= [name,two,three,one,five,four];
return arr;
}
}