QML error on exposing child properties

Viewed 2454

I have a QML object defined as follows:

Item {
    property alias source: a.internalImage.source
    property alias text: a.internalText.text

    Column {
        id: a

        Image {
            id: internalImage
        }

        Text {
            id: internalText
            width: internalImage.width
        }
    }
}

This fails with: Invalid alias target location: internalImage.

However, if I do:

Column {
    property alias source: internalImage.source
    property alias text: internalText.text

    Image {
        id: internalImage
    }

    Text {
        id: internalText
        width: internalImage.width
    }
}

Why is that?

2 Answers

I did solve this issue by creating a simple property and a changeListener

Item {
    property string source: a.internalImage.source
    property string text: a.internalText.text

    onSourceChanged: a.internalImage.source = source
    onTextChanged: a.internalText.text
}

I hope this helps

Related