Create alias to child's property



  • Hello. Excuse me for such stupid question but I still cannot understand the next thing.
    My code:

    import QtQuick 2.0
    
    Item {
        property alias aaa: headCell.text;
        ListModel {
            id: lmodel;
            ListElement {
                v1: "15"
            }
        }
    
        Component {
            id: cellDelegate
            Item {
                width: 30
                height: 60
                Column {
                     Rectangle {
                        border.width: 1
                        width: 30
                        height: 30
                        Text {
                            text: v1
                            anchors.centerIn: parent
                        }
                     }
                  }
              }
        }
    
        ListView{
            id: gvTable
            model: lmodel
            delegate: cellDelegate
            width: 90
            height: 30
            header: Column{
                Rectangle{
                    border.width: 1
                    width: 30
                    height: 30
                    Text {
                        id: headCell
                        anchors.centerIn: parent
                    }
                }
            }
        }
    }
    

    The error in line

    property alias aaa: headCell.text;
    

    Invalid alias reference. Unable to find id "headCell"

    I understand that I'm trying to get access to the value that locate into property of child object. Is this reason of error, right? So what is the way to get access to property I need?

    Thanks.



  • You can achieve this by having a string property in root level.
    See the updated code below.

    import QtQuick 2.0

    Item {
    //property alias aaa: headCell.text;

    property string headerText
    
    ListModel {
        id: lmodel;
        ListElement {
            v1: "15"
        }
    }
    
    Component {
     ...................
     .............
    }
    
    ListView{
        id: gvTable
        model: lmodel
        delegate: cellDelegate
        width: 90
        height: 30
        header: Column{
            Rectangle{
                border.width: 1
                width: 30
                height: 30
                Text {
                    id: headCell
    		text:headerText
                    anchors.centerIn: parent
                }
            }
        }
    }
    

    }



  • Thank you, this works.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.