Get items after loading a qml file using the Loader QML



  • What is the best way to get an item in a different QML file?

    I have something like that:

    @
    Button {
    text: qsTr("text")
    onClicked: {
    onClicked: circleLoader.source = "circle.qml";
    }
    }
    @

    And I am getting the attribute width in circle.qml - this file has many rectangles - using this line of code:

    @
    circleLoader.children[0].width
    @

    Does anyone know a better way of doing this?

    Thanks!


  • Moderators

    Hi,

    Try with circleLoader.item.width



  • Yes, that works, but I get the value for the first item in circle.qml.

    For example, if I have two items, how can I get the width for the second item?


  • Qt Champions 2017

    You can access the children object of Item. That is the only way. Your posting already included this.

    You can try with only this as you have done it.

    @ console.log(pageL.item.children[0].width)
    console.log(pageL.item.children[1].width)
    @



  • [quote author="Dheerendra" date="1407907351"]You can access the children object of Item. That is the only way. Your posting already included this.

    You can try with only this as you have done it.

    @ console.log(pageL.item.children[0].width)
    console.log(pageL.item.children[1].width)
    @[/quote]

    OK, thank you very much.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.