Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]QML->C++ Pass associative array
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ixSci
    wrote on 19 Jan 2012, 04:27 last edited by
    #1

    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!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      srikanth_trulyit
      wrote on 20 Jan 2012, 08:37 last edited by
      #2

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ixSci
        wrote on 23 Jan 2012, 10:40 last edited by
        #3

        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 Reply Last reply
        0

        1/3

        19 Jan 2012, 04:27

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved