Passing structured data between C++ and QML/JavaScript



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



  • 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


Log in to reply
 

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