List property and dynamic objects

  • 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)?

  • 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)
       il = someItemArray;
       // push c2
       for (var i = 0; i < il.length; ++i)
       il = someItemArray;
       for (var i = 0; i < il.length; ++i) console.log("il[i] = " + il[i]);


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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.