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

Id's that share names



  • Lets say I have the following code:

    Item
    {
      id: foo
      Rectangle
      {
        id: red
      }
    }
    
    Item
    {
      id: bar
      Rectangle
      {
        id: red
      }
    }
    

    how is this shared id resolved? I am wondering if I can use the same id for in different places as it would be convenient for me but I don't want them to try to reference one another and I don't want to get the compiler confused. It seems as thought I am allowed to do it but perhaps I shouldn't?



  • so, why not simply rename the second id as 'red1' and crack on with what you were doing...?



  • @RobM if you're trying to reuse a Rectangle component over and over, you may want to take a look at the QML Camera example, to see how the buttons (Focus, Camera settings, Video control and so on) are created from a base CameraButton component.

    If not, use common sense regarding id naming.


Log in to reply