Important: Please read the Qt Code of Conduct -

individual IDs for components that loaded from same file.qml

  • 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

  • Hi! A very simple solution could be this:


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


    ApplicationWindow {
      property int globalCounter: 0
      yourFunction() {
         // ...
         var object  = component.createObject(container, {"x": 0, "y": 0, "someIdentifier": ++globalCounter});

  • i use it

Log in to reply