Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. individual IDs for components that loaded from same file.qml

individual IDs for components that loaded from same file.qml

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 610 Views 1 Watching
  • 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.
  • AlperA Offline
    AlperA Offline
    Alper
    wrote on last edited by Alper
    #1

    Hi

    i have a qml code:

            function createComponent(){
                var component = Qt.createComponent("file:MyFile.qml");
                var object  = component.createObject(container, {"x": 0, "y": 0});
            }
    

    i want to each time that i call createComponent() from C++, set an individual id (or any identifier property) to the component.(individual identifiers to manage them from C++)
    How do it?

    thanks in advance

    ? 1 Reply Last reply
    0
    • AlperA Alper

      Hi

      i have a qml code:

              function createComponent(){
                  var component = Qt.createComponent("file:MyFile.qml");
                  var object  = component.createObject(container, {"x": 0, "y": 0});
              }
      

      i want to each time that i call createComponent() from C++, set an individual id (or any identifier property) to the component.(individual identifiers to manage them from C++)
      How do it?

      thanks in advance

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! A very simple solution could be this:

      MyFile.qml

      Item {
        property int someIdentifier: 0
        // ...
      }
      

      main.qml

      ApplicationWindow {
        property int globalCounter: 0
      
        yourFunction() {
           // ...
           var object  = component.createObject(container, {"x": 0, "y": 0, "someIdentifier": ++globalCounter});
      }
      }
      
      1 Reply Last reply
      2
      • AlperA Offline
        AlperA Offline
        Alper
        wrote on last edited by
        #3

        i use it
        TNX

        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