[Solved] Array in ListElement?



  • Hi,

    I would like to assign a variable size array of strings as a property to a ListElement, however I cannot see how this needs to be done.
    My code currently looks as follows for one of the elements:
    @
    ListModel {
    ListElement {
    pLabel: "label"
    pValues: [ "a", "b" ]
    }
    }
    @
    When I run this assigned to a ListView, I get the following runtime error:
    "ListElement: cannot use script for property value "

    Can anyone tell me how to do this correctly?

    Thanks



  • Found it myself:
    @
    ListModel {
    ListElement {
    pLabel: "label"
    pValues: [
    ListElement { pValue: "a" },
    ListElement { pValue: "b" }
    ]
    }
    }
    @

    It's so simple yet there is not a single mention of this in the QML documentation. I really hope Nokia improves it significantly for the next releases. It is currently nowhere near the quality that I am used to from the C++ Qt docs.



  • Hi,

    Sorry to hear you are finding the documentation lacking. Improvements have been ongoing since the initial 4.7 release, so in general you will find more information using "4.7-snapshot" rather than "4.7" (for example, see http://doc.qt.nokia.com/4.7/qtbinding.html vs. http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html). From what I understand the doc team is also at work on some significant improvements to the QML docs, so hopefully you will find things much improved soon.

    Embedding lists should be covered in the ListModel documentation (http://doc.qt.nokia.com/4.7-snapshot/qml-listmodel.html, see the detailed description) -- any suggestions for where else we should document this to make it more accessible?

    Thanks for the feedback.

    Regards,
    Michael



  • I just want to add a small detail, which took me some time to figure out. In the example:

    @ ListModel {
    id: myModel;
    ListElement {
    pLabel: "label"
    pValues: [
    ListElement { pValue: "a" },
    ListElement { pValue: "b" }
    ]
    }
    }@

    You would access the values "a" and "b" by writing:

    @ myModel.pValues.get(0).pValue // Equal to "a"
    myModel.pValues.get(1).pValue // Equal to "b"@

    Regards,

    Julian


Log in to reply
 

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