I have QSqlQueryModel and QTableView to display data. View is set to SelectRows and SingleSelection mode. Sorting by column is enabled in my view. By default query result is sorted by id. Sorting is working well, but when I sort my data by some column and try to get some data from selected row, the program returns me the data which would be returned if the table was sorted by id! I use following code to get data (0 is id column number):

Qt Code:
  1. int id = model->data(model->index(table->currentIndex().row(), 0)).toInt()
To copy to clipboard, switch view to plain text mode 

How to get really selected data?

Simpliest example to be more clear: the query returned me table sorted by id:

id | price
1 | 100
2 | 50
3 | 120

I'm sorting table by price column in ascending order, selecting first row and hoping to get id = 2 and price = 50, but program returns me id = 1 and price = 100. What's to do?