Acessing childrens by ID?
-
Hello as... as I have complex:
main.qml:
ApplicationWindow { id: mainWindow // here is where i need to get the TextFiled text set as "something" // Views (initialy used SwipeView) StackLayout { id: view anchors.fill: parent currentIndex: 0 Item { id: view_InitialScreen InitialScreen {} } Item { id: view_ChoiseOffline ChoiseOffline {} } } }ChooseOffline.qml:
Rectangle { id: parentObject anchors.fill: parent Rectangle { id: testRect Rectangle { id: preselectedStrloRectangle Rectangle { id: scanRectangle Image { id: scanImage } } Rectangle { id: preselectedStrloRectangle1 Label { id: preselectedStrloLabel1 } } Rectangle { id: preselectedStrloRectangle2 TextField { id: preselectedStrloTextfield2 text: "something" } } Rectangle { id: preselectedStrloRectangle3 Image { id: clearImage } } } Rectangle { id: serialNumberRectangle Rectangle { id: serialNumberRectangle1 Label { id: serialNumberLabel1 } } Rectangle { id: serialNumberRectangle2 TextField { id: serialNumberTextfield2 } } } ... and so on }so far the only way I was able to console.log() the text value is by:
console.log(view_ChoiseOffline.children[0].children[0].children[0].children[2].children[0].text)but this is a terrible solution as Im keep adjuting the code, adding more childrens above and bellow so this would constantly change...
everytime i try to use IDs instead of children[int] i get an error that Cannot read property xxxx of undefined.
i have tried to use difenret id name instead of children[0], or simply children[parentObject]/children['parentObject'] or ucing "item" instead of "children".so is there any way to access it simply by ID(s) out of the main.qml?
-
What you could do is inside of your ChooseOffline.qml and inside of parentObject, define an alias for the text you want to access:
property alias preselectedTextfield: preselectedStrloTextfield2
and then from main.qml you can access it with view_ChoiseOffline.preselectedTextfield.text
-
What you could do is inside of your ChooseOffline.qml and inside of parentObject, define an alias for the text you want to access:
property alias preselectedTextfield: preselectedStrloTextfield2
and then from main.qml you can access it with view_ChoiseOffline.preselectedTextfield.text
@Marko-Stanke said in Acessing childrens by ID?:
What you could do is inside of your ChooseOffline.qml and inside of parentObject, define an alias for the text you want to access:
property alias preselectedTextfield: preselectedStrloTextfield2
and then from main.qml you can access it with view_ChoiseOffline.preselectedTextfield.text
well this does not work... however what I have managed to make it work is to set the alias inside parentObject:
property alias aliasPreselectedLocation: preselectedStrloTextfield2which Im able to call from mainWindow via:
view_ChoiseOffline.children[0].aliasPreselectedLocation.textdefinitely not nice way, but at least it works...
but back to my question... can I use children with string value (of ID idealy) instead of integer counter?
something like:children['parentObject']I tried several ways but i have never made it work
-
how about:
main.qml:
ApplicationWindow { id: mainWindow // here is where i need to get the TextFiled text set as "something" // Views (initialy used SwipeView) StackLayout { id: view anchors.fill: parent currentIndex: 0 Item { id: view_InitialScreen InitialScreen {} } Item { id: view_ChoiseOffline ChoiseOffline {id:chOffline;} } } }ChooseOffline.qml:
Rectangle { id: parentObject anchors.fill: parent property alias aliasPreselectedLocation: preselectedStrloTextfield2 .... }console.log(chOffline.aliasPreselectedLocation.text)