PDA

View Full Version : QTableView, QSqlTableModel and ProxyModel not the same row



AlmAck
6th January 2009, 19:30
I'm using a QSqlTableModel to read and write data to a sqlite database. At this model I apply a costum SortFilterProxyModel, the result is diplayed in a QTableView. My problem is:
I want to eliminate a line selected by the user on the database. Without the sorting the user select the line and then I delete it directly from the model with modelTable->removeRow(index.row ()).
If now I enable setSortingEnabled(true) in the QTableView or I use the SortFilterProxyModel to isolate some characters, the order of the row change and it is not the same of the model. It doesn't allow me to delete a line from the model with removeRow because the row number of the Table is not the same row number of the Model.

How do I have to do for resolving the problem? have I perhaps mistaken approach?

Thanks in advance
(excuse for my bad English)

jpn
6th January 2009, 19:45
QAbstractProxyModel provides means for mapping indexes from and to the source model. See

QAbstractProxyModel::mapToSource()
QAbstractProxyModel::mapFromSource()

AlmAck
6th January 2009, 20:55
Thanks a lot! was exactly what I need.