Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved]How to Create ListModel in runtime

    QML and Qt Quick
    2
    5
    6306
    Loading More Posts
    • 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
      Milnadar last edited by

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

      1 Reply Last reply Reply Quote 0
      • M
        maxpayne last edited by

        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 Reply Quote 0
        • M
          Milnadar last edited by

          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 Reply Quote 0
          • M
            maxpayne last edited by

            hi,

            I've edited my reply accordingly.

            thanks,
            Max

            1 Reply Last reply Reply Quote 0
            • M
              Milnadar last edited by

              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 Reply Quote 0
              • First post
                Last post