Qt 6.11 is out! See what's new in the release
blog
Resolving a QML settings id problem
-
I have a conundrum with Settings. It seems it can only work when the id of the variable is referenced. Using
parentdoes not work. So this means that the ID has to be known inside the component. However, if the id is set inside the component, then it is not available outside the component. See the belowMyComponent.qml
Item { id: myItem property int myNumber Settings { property alias myNumber: myItem.myNumber } }main.qml
ApplicationWindow { MyComponent { } Rectangle { id: rect property real number: myItem.myNumber } }This will fail because the
idmyItem is not available toRectanglerect.However, if I try the below, then it fails because
Settingsdoesn't know where to look to findmyItem.MyComponent.qml
Item { property int myNumber Settings { property alias myNumber: myItem.myNumber } }main.qml
ApplicationWindow { MyComponent { id: myItem } Rectangle { id: rect property real number: myItem.myNumber } }What can be done to solve this, aside from locating the Settings component such that it is at the root of both
MyComponentandRectanglecomponents?