1

https://gist.github.com/eyllanesc/4f47e4f59100340b8328438a39011b31

I used this link to generate a QAbstractList and a SortProxyModel over it. I sorted the list with any one attribute using sortdata method in sortproxymodel class. I also need to access some data from that list for some computations in main.qml. console.log(PersonModel.data(1,'value1')) is the line that I used. Is it wrong?

June7
  • 19,874
  • 8
  • 24
  • 34
Neethu
  • 69
  • 1
  • 11

1 Answers1

0

If you want to access the information you must pass a QModelIndex and the role:

def data(self, index, role=Qt.DisplayRole):

In your case it should be similar to the following:

mymodel.data(mymodel.index(number_of_row, 0), value_of_role)

For example to the previous .qml I have added modifications and the most important is the following code:

Row{
    id: row2
    height: 40
    anchors.bottom: parent.bottom
    spacing: 100
    ComboBox {
        id: comboBoxRole2
        width: 150
        model: [ "name", "value1", "value2", "value3", "value4"]
    }

    ComboBox {
        id: number
        width: 150
        model: mymodel.rowCount()
    }

    Label{
        id: output
        text: mymodel.data(mymodel.index(number.currentIndex, 0), Qt.UserRole+1 + comboBoxRole2.currentIndex)
    }
}

You can find the complete example in the following link.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241