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] Array in ListElement?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Array in ListElement?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 9.9k 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.
  • J Offline
    J Offline
    joejoejoejoe
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joejoejoejoe
      wrote on last edited by
      #2

      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.

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

        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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JulianS
          wrote on last edited by
          #4

          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

          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