How to bind the listview using listelement with dynamic values?



  • Hi all,

    I want to bind the listelement from .cpp file. The code below is static. I have an .xml file with itemTitle,ImageURL,itemId and I can read from xml. Now I want to pass the value from .cpp to .qml

    Query:
    1.What is the return type has to mention in .cpp file to bind with list element?
    2. How to bind the return type in ListElement component in .qml file.

    If possible code snippet please.

    Code Snippet:

    ListElement { itemTitle: "Housing with Mortgages"; imageUrl: "qrc:/Samples/Maps/OpenExistingMap/Housing.png"; itemId: "2d6fa24b357d427f9c737774e7b0f977"}
    ListElement { itemTitle: "USA Tapestry Segmentation"; imageUrl: "qrc:/Samples/Maps/OpenExistingMap/Tapestry.png"; itemId: "01f052c8995e4b9e889d73c3e210ebe3"}
    ListElement { itemTitle: "Geology of United States"; imageUrl: "qrc:/Samples/Maps/OpenExistingMap/geology.jpg"; itemId: "74a8f6645ab44c4f82d537f1aa0e375d"}

    Thanks in advance.


  • Moderators

    @Mathan-M Why do you want to bind to ListElement?
    ListElement's are added to ListModel.
    You should probably try to access this model from C++. ListModel is also a QAbstractItemModel.