0
votes

I have a ListModel in Qml which is filled dynamically.

I would like to know how can I retrieve information regarding a row from the model when I do myModel.get(i). This returns an object but I do not know how to extract information from it. In the docs I saw all example with myModel.get(i)."something". But I do not have any field to call, I would like something like :

function getValue(i,columnIndex)
{
    var obj =  myModel.get(i)
    var requestedValue = obj[columnIndex]
}

Thanks

1
What do you mean by "I do not have any field to call", how did you write your ListModel ?GrecKo
ListModel { id:myModel }vio br
and how do you populate it ?GrecKo
When a user clicks on a row in a table view, the row is processed and the result is appended to myModel.vio br
My point is that you should have roles to call, columnIndex doesn't make sense for a ListModel.GrecKo

1 Answers

1
votes

When you want to access the attributes you must do it through the name of that attribute. For example

ListModel {
        id: myModel
        ListElement {
            title: "Moby-Dick"
            author: "Herman Melville"
        }
        ListElement {
            title: "The Adventures of Tom Sawyer"
            author: "Mark Twain"
        }
}

You can access it in two ways:

{your Model}.get({index}).title
{your Model}.get({index})['title']