Luca
Luca

Reputation: 10996

QML error on exposing child properties

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?

Upvotes: 5

Views: 2579

Answers (2)

Engel
Engel

Reputation: 199

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

Upvotes: 0

skypjack
skypjack

Reputation: 50540

As from the documentation, the scope of a Component is:

the union of the object ids within the component and the component's root element's properties

So, the outer element is not allowed to access to the ids contained in the inner element by means of a chain of ids.
On the other side, if you explicitly export a bunch of parameters by means of a set of variables, those values/references are freely available to the outer component.

Upvotes: 4

Related Questions