[SOLVED]QML->C++ Pass associative array
QML and Qt Quick
3
Posts
2
Posters
4.5k
Views
1
Watching
-
wrote on 19 Jan 2012, 04:27 last edited by
Hi there,
I'd like to pass an array of pairs(key, value) from QML to the C++ side. How can I achieve that?
Thanks!
-
wrote on 20 Jan 2012, 08:37 last edited by
Not sure if there is a direct conversion from associative arrays in JS to map in Qt. But you can do it by populating your array into a JS object and send it across.
@
var mymap = new Array;
mymap["one"] = 1;
mymap["two"] = 2;
var myObj = new myObject;
for (var key in mymap) {
myObj[key] = mymap[key];
}
cppEngine.setMap(myObj); // prototype is void setMap(QVariantMap map)
@ -
wrote on 23 Jan 2012, 10:40 last edited by
Hi srikanthsombhatla, thanks for the hint to QVariantMap, I've solved it this way:
@cppEngine.setMap({"one" : 1, "two" : 2}); // prototype is void setMap(QVariantMap map)@
1/3