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

has a relationship in QML



  • hello

    here is an example,

    one.qml //filename

    Rectangle
    {

    }
    
    
    two.qml // filename
    
    one
    {
    

    }

    three.qml // filename

    one
    {

    }
    
    
    is this has a re;ationship or inhertance?.

  • Qt Champions 2016

    inhertance


  • Moderators

    Hi @Pradeep-Kumar
    Honestly I too had never thought of inheritance and relationship in QML but Ill try to explain.
    Accroding to your code:

    • Adding One in Two and Three makes a has-a relationship between them i.e Two and Three contains (has i.e has a relationship) One.
    • I think there is no inheritance in between them.

    Now in QML terms according to me inheritance would be something like this:
    One.qml

    Rectangle {
     width: 50
     height: 50
     color: "red"
    }
    

    Two.qml

    One {
     width: 200
     height: 200
     property string myProperty
     Text {
       anchors.centerIn: parent
       text: "Two"
     }
    }
    

    Now here Two extends One which means it extends the Rectangle plus has its own properties as well and also contains new element Text. If you run Two.qml you will see it will be of width and height 200 but it will have its color "red" which it inherited from One.qml. This means Two inherited the color property as well has have it own new properties.


  • Banned

    This post is deleted!

  • Banned

    This post is deleted!

Log in to reply