Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML error on exposing child properties

Tags:

c++

qt

qml

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?

like image 271
Luca Avatar asked Sep 25 '22 04:09

Luca


1 Answers

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.

like image 92
skypjack Avatar answered Sep 29 '22 06:09

skypjack