Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. has a relationship in QML
Forum Update on Monday, May 27th 2025

has a relationship in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 5 Posters 2.2k Views
  • 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    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?.

    Pradeep Kumar
    Qt,QML Developer

    p3c0P 1 Reply Last reply
    0
    • benlauB Offline
      benlauB Offline
      benlau
      Qt Champions 2016
      wrote on last edited by
      #2

      inhertance

      1 Reply Last reply
      1
      • Pradeep KumarP Pradeep Kumar

        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?.
        p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        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.

        157

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Mereteran
          Banned
          wrote on last edited by Mereteran
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • S Offline
            S Offline
            sarah168
            Banned
            wrote on last edited by
            #5
            This post is deleted!
            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