Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use the date in QML files loaded by LOADER element in my main QML files



  • anxious :(


  • Moderators

    If you mean "data" instead of "date" then you are looking for "item" property.
    @
    Loader {
    id: myLoader
    source: "someFile.qml"
    }

    // somewhere else in code
    myLoader.item.someProperty // will return the value of "someProperty"
    @



  • [quote author="sierdzio" date="1377087064"]If you mean "data" instead of "date" then you are looking for "item" property.
    @
    Loader {
    id: myLoader
    source: "someFile.qml"
    }

    // somewhere else in code
    myLoader.item.someProperty // will return the value of "someProperty"
    @[/quote]
    yes i know what you said and thank u. but now there is a listview element in B.qml and i wanna use the currentIndex property of listview element of b.qml in A.qml.so using "loader.item.***"can't achieve my goal.and we can't also use "loader.item.listview.currentindex"... am i clear?- -


  • Moderators

    No. Do you get any error messages? It really should work, but exact details depend on your setup.



  • [quote author="sierdzio" date="1377164039"]No. Do you get any error messages? It really should work, but exact details depend on your setup.[/quote]
    ...no error message.
    and in b.qml,the listview element is not the root item. so "myloader.item.currentIndex"can't work but "myloader.item.mylistview.currentIndex"is illegal...so i dont konw how to deal with it ...


  • Moderators

    So add an intermediate step:
    @
    // B.qml
    Item {
    property int currentIndex: 0

    ListView {
    id: mylistview
    currentIndex: parent.currentIndex
    }
    }
    @

    Anod now use myloader.item.currentIndex.





  • [quote author="sierdzio" date="1377164777"]So add an intermediate step:
    @
    // B.qml
    Item {
    property int currentIndex: 0

    ListView {
    id: mylistview
    currentIndex: parent.currentIndex
    }
    }
    @

    Anod now use myloader.item.currentIndex.[/quote]
    ...this means inital a currentIndex to 0 and assign 0 to mylistview.currentIndex.when using"myloader.item.currentIndex",it==0


  • Moderators

    I don't understand you. With the code above, you can run this in your buttons:
    @
    onButton1Clicked: myloader.item.currentIndex = 3; // sets the index to 3

    onButton2Clicked: myloader.item.currentIndex = 8; // sets the index to 8
    @


Log in to reply