Qt Forum

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

    List property and dynamic objects

    QML and Qt Quick
    2
    2
    1666
    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.
    • K
      Kxyu last edited by

      Hi! I've got a question about dynamic object creation. So, my goal is to create some dynamic objects and store them in a property like @property list<Item> items@
      but when i try to assign something to it, it has no effect! @items[0]=myComponent.createObject(someObject)@
      is there a way do it (to append something to the list)?

      1 Reply Last reply Reply Quote 0
      • C
        chriadam last edited by

        Are you using QtQuick 1.x or QtQuick 2.0? With QtQuick 2 you can use a "var" property to store an array of items which can be dynamically added to etc. ListReference properties are generally intended to be lightweight and "static", I believe.

        /edit: turns out that you can do:

        @
        property list<Item> il
        Component.onCompleted: {
        // define array
        var someItemArray = [];

           // push c1
           for (var i = 0; i < il.length; ++i)
               someItemArray.push(il[i]);
           someItemArray.push(c1);
           il = someItemArray;
        
           // push c2
           for (var i = 0; i < il.length; ++i)
               someItemArray.push(il[i]);
           someItemArray.push(c2);
           il = someItemArray;
        
           for (var i = 0; i < il.length; ++i) console.log("il[i] = " + il[i]);
        

        }
        @

        [Edit: Used proper @ code formatting. -mlong]

        1 Reply Last reply Reply Quote 0
        • First post
          Last post