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. Creating Lists dynamically
Forum Update on Monday, May 27th 2025

Creating Lists dynamically

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 4.8k Views
  • 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.
  • S Offline
    S Offline
    sruthihsr
    wrote on 28 Nov 2011, 05:11 last edited by
    #1

    Hi I want to create lists dynamically with names received from C++. Please let me know how to go about it

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RazrFalcon
      wrote on 28 Nov 2011, 05:13 last edited by
      #2

      You mean something like this:
      http://developer.qt.nokia.com/forums/viewthread/11330/P15/#62719
      ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sruthihsr
        wrote on 28 Nov 2011, 06:26 last edited by
        #3

        HI thanks for the reply.
        What i want is have a display dimensional form like below
        and the number of lists ie (Alist ,Blist,Clist is dynamic is realtime) and the items within the list a1,a2,a3 are also real time.
        Tell me how do I create them dynamically and access it in Qml.
        I am open to any approach
        Alist a1,a2,a3
        Blist b1,b2,b3
        Clist c1,c2

        1 Reply Last reply
        1
        • D Offline
          D Offline
          diro
          wrote on 28 Nov 2011, 06:57 last edited by
          #4

          For dynamic list, there are many ways to archive it.

          1. http://doc.qt.nokia.com/latest/qml-qt.html#createQmlObject-method
          2. "http://cdumez.blogspot.com/2010/12/expose-nested-c-models-to-qml.html":http://cdumez.blogspot.com/2010/12/expose-nested-c-models-to-qml.html

          For dynamic item:
          @ListModel
          {
          id:vip_list;
          ListElement{name:"aaa";status:"invalid"; time:"2011-01-15..."}
          ListElement{name:"bbb";status:"invalid"; time:"2011-11-11..."}
          }@

          JS code:
          @vip_list.append({name:"ccc", status:"ok", time:"2011-01-01"});@

          For most case, you may combine the above with signal:
          JS code:
          @onDataReceived:
          {
          vip_list.append({name:PARAM1_FROM_SIGNAL, status:PARAM2_FROM_SIGNAL, time:PARAM3_FROM_SIGNAL});
          }@

          For access, you can try
          @vip_list.get(index).name
          vip_list.get(index).status
          vip_list.get(index).time@
          Please refer to "http://doc.qt.nokia.com/4.7-snapshot/qml-listmodel.html":http://doc.qt.nokia.com/4.7-snapshot/qml-listmodel.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sruthihsr
            wrote on 28 Nov 2011, 07:13 last edited by
            #5

            Hi, Hi,
            I have a situation where i have to display multiple lists corresponding to
            different parent.

            Alist A1 | A2| A3 | A4
            Blist B1 | B2| B3
            CList C1 | C2
            DList D1 | D2| D3 |D4

            The parents and the child elements i get are in different vectors.
            I will have to classify them into different lists based on the parent id and
            display them in qml.
            The number of parent elements and number of child elements are variable.

            I am able to do the appending through C++.

            suppose i create a master list which has lists in it

            @
            masterlist[0] ="A",list[A1 , A2, A3 , A4]
            masterlist[1] ="B",list[B1 , B2, B3 ]
            masterlist[2] ="C",list[C1 , C2 ]
            masterlist[3] ="D",list[D1 , D2, D3 , D4]
            @

            how do I access the list from my Qml like model :materlist.sublist.
            You can suggest any other approach

            [EDIT: code formatting, please wrap in @-tags, Volker]

            1 Reply Last reply
            0

            1/5

            28 Nov 2011, 05:11

            • Login

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