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]How to Create ListModel in runtime
QtWS25 Last Chance

[Solved]How to Create ListModel in runtime

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 6.6k 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.
  • M Offline
    M Offline
    Milnadar
    wrote on last edited by
    #1

    Tell me please how to create a ListModel in runtime and to keep it's handle

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxpayne
      wrote on last edited by
      #2

      To create a model at runtime use a component and instantiate it:
      http://doc.qt.nokia.com/4.7-snapshot/qdeclarativedynamicobjects.html

      This may also work :

      http://cdumez.blogspot.com/2010/11/heterogeneous-list-model-in-qml.html

      Next,
      use model.append() to add dynamic data to your model....you can call this from a javascript function..something like this:
      //this is just pseudo code...

      @
      myFunction()
      {
      var data = ["1","2","3","4","5","6","7","8"];
      var i = 0;
      for (i=0; i<data.length; i++){
      model.append({"digit": data[i]}); //here digit is a role
      }
      }
      @

      in your delegate, your data can now be accessed through the digit role.

      @delegate:
      Text {
      color: "red"
      text: digit + "index=" + " " +index
      }@

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

        Excuse me that i has written not clearly.
        I meant i need to create the ListModel object itself.

        ex:

        By pressing the Button1 the ListModel is created,
        By pressing the Button2, i can now set ListView.model to this new List Model i was created

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxpayne
          wrote on last edited by
          #4

          hi,

          I've edited my reply accordingly.

          thanks,
          Max

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Milnadar
            wrote on last edited by
            #5

            Thanks for your help.
            At last i created that object)

            And i hope the last question is how to manipulate that object?

            Take parent and compare all it's children to find the object i created, or there is some other way to handle it?

            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