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. List property and dynamic objects

List property and dynamic objects

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

    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
    0
    • C Offline
      C Offline
      chriadam
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved