Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Access a specific object



  • I have created 10 objects in a for loop, and now I want to access for example the third one.
    Here's the code used for creating:

    for (var i = 0; i < 10; i++) {
         var comp = Qt.createComponent("Rand.qml");
         var en = comp.createObject(root, {x: i, y: i*50});
    }
    

    Is there a way to access the third one and change its y coordinate (other than manually giving every object an specific id, which would be hard if there were like 100 of them) ?


  • Qt Champions 2017

    property variant items:[]

    items[i] = comp.createObject(root, {x: i, y: i*50});

    Now you can access the any objects in items using index.


  • Qt Champions 2017

    property variant items:[]

    items[i] = comp.createObject(root, {x: i, y: i*50});

    Now you can access the any objects in items using index.


Log in to reply