March 23, 2012

Kxyu Kxyu
Lab Rat
139 posts

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

  1. property list<Item> items

but when i try to assign something to it, it has no effect!
  1. items[0]=myComponent.createObject(someObject)

is there a way do it (to append something to the list)?

1 reply

March 26, 2012

chriadam chriadam
Lab Rat
178 posts

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:

  1.     property list<Item> il
  2.    Component.onCompleted: {
  3.        // define array
  4.        var someItemArray = [];
  5.  
  6.        // push c1
  7.        for (var i = 0; i < il.length; ++i)
  8.            someItemArray.push(il[i]);
  9.        someItemArray.push(c1);
  10.        il = someItemArray;
  11.  
  12.        // push c2
  13.        for (var i = 0; i < il.length; ++i)
  14.            someItemArray.push(il[i]);
  15.        someItemArray.push(c2);
  16.        il = someItemArray;
  17.  
  18.        for (var i = 0; i < il.length; ++i) console.log("il[i] = " + il[i]);
  19.    }

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

 
  ‹‹ Connecting C++ signal to QML function with arguments      [SOLVED]How can I create TextArea element in desktop application ››

You must log in to post a reply. Not a member yet? Register here!