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

Component objects cannot declare new properties



  • If I don't use Button element in the Component, it doesn't give me the above error.

    e.g. This works fine

    Component {
    
      Row {
            Rectangle {..}
            Rectangle {..}
            Rectangle {..}
            Rectangle {..}
       }
    }
    

    But if I add Button element as below, it gives me the mentioned error in the application output

    Component {
          id: itemDelegate
          Button { .. }
          Row {
                Rectangle {..}
                Rectangle {..}
                Rectangle {..}
                Rectangle {..}
           }
    }
    

    I'm using the Component as a delegate



  • @pingal said in Component objects cannot declare new properties:

    But if I add Button element as below, it gives me the mentioned error in the application output

    AFAIK, Component can hold only 1 root object (eg. Item, Rectangle, Row ect.). It is same a creating a QML file for a component (cf. https://doc.qt.io/qt-5/qml-qtqml-component.html)
    You should change your code to:

    Component {
        id: itemDelegate
        Item {
            Button { .. }
            Row {
                Rectangle {..}
                Rectangle {..}
                Rectangle {..}
                Rectangle {..}
            }
      }
    }
    

Log in to reply