What C++ types correspond to QML types?



  • To what C++ types do the following QML types correspond? In other words, what are the appropriate C++ method parameters types or return types? Should C++ values, references or pointers be used?
    @
    {"Key1": "Value1", "Key2": "Value2"}
    @

    @
    {Key1: "Value1", Key2: "Value2"}
    @

    @
    ["Value1", "Value2"]
    @

    @
    [{"Key1": "Value1", "Key2": "Value2"}, {"Key3": "Value3", "Key4": "Value4"}]
    @

    @
    [["Value1", "Value2"], ["Value3", "Value4"]]
    @

    etc.

    Is there any documentation or examples of this?

    In addition, when are QStringList, QList, QLinkedList, QMap, etc. used? When are C++ (i.e., non-Qt) collection classes used like those in STL?


  • Moderators

    Hi,

    See "Interacting with QML Objects from C++":http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html -- Data is passed between C++ and QML using QVariant, and it is passed by-value (no pointers or references).

    These pages might be of interest to you too:

    [quote author="SteveG" date="1403299415"]In addition, when are QStringList, QList, QLinkedList, QMap, etc. used? When are C++ (i.e., non-Qt) collection classes used like those in STL? [/quote]QML uses JavaScript types. In the examples you gave, curly braces represent JavaScript objects (stored as QMap) and square braces represent JavaScript arrays (stored as QList).

    Note: QStringList is simply a typedef of QList<QString>.

    Qt uses Qt containers, not STL containers. Also, I don't think QLinkedList is used in QML.


Log in to reply
 

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