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. Access a specific object
Qt 6.11 is out! See what's new in the release blog

Access a specific object

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 267 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.
  • M Offline
    M Offline
    mitrovicl
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      property variant items:[]

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

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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      2

      • Login

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