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. Passing structured data between C++ and QML/JavaScript
Qt 6.11 is out! See what's new in the release blog

Passing structured data between C++ and QML/JavaScript

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 11.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.
  • _ Offline
    _ Offline
    _mh_
    wrote on last edited by
    #1

    What is the recommended way to pass structured data from C++ side to QML/JavaScript side and vice versa? QVariantMap? I found the following lines from the QtWebKit documentation. Does this apply to QML too?:

    JavaScript compound objects, also known as JSON objects, are variables that hold a list of key-value pairs, where all the keys are strings and the values can have any type. This translates very well to QVariantMap, which is nothing more than a QMap of QString to QVariant.

    The seamless conversion between JSON objects and QVariantMap allows for a very convenient way of passing arbitrary structured data between C++ and the JavaScript environment. The native QObject has to make sure that compound values are converted to QVariantMaps and QVariantLists, and JavaScript is guaranteed to receive them in a meaningful way.

    Note that types that are not supported by JSON, such as JavaScript functions and getters/setters, are not converted.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      The "Exposing Data" section of "http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html":http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html gives an explanation of several recommended ways of passing data between C++ and QML.

      Regards,
      Michael

      1 Reply Last reply
      0

      • Login

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