[SOLVED]QML->C++ Pass associative array



  • 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!



  • 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)
    @



  • 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)@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.