[Qt-interest] QSqlTableModel and getting a QModelIndex based ona primary key.

MARTIN Pierre hickscorp at gmail.com
Mon Sep 26 19:17:36 CEST 2011


Hello Scott and list,

> Two different issues...
> As to the filter, if you applied it only to the single view where you
> need it..  or even use it outside the view using a proxy filter, the
> original views wouldn't be hurt by it.
That's right, using a proxy model can come in handy.

> As to your issue, if your DB is larger than the fetch size used by
> sqltablemodel, without using a where clause in your sql, you will need
> to do a fetchmore loop until the index id is read in you wont be able to
> get the ID.
Yes, hence my question about the canFetchMore / fetchMore.

> Now, what I have done in the past and YMMV, is if my QSqlTableModel
> query is sorted by idx, so idx == row of the QModelIndex, I will use a
> separate QSqlQuery to find the id, and guess the QModelIndex, but that
> only works on small  dbs with no filtering and no sorting
i believe this is wrong, because if a record got deleted in the middle of the table, the QModelIndex row will be different than the primary key.

About my issue itself, i have kind of figured a draft solution already. i'm instanciating a 2nd model on the same table, so any filtering i do on it is not related to any view. This is almost the same as using a proxy, and suits my needs because i'm only using it read-only, so there are no commits to notify to the other model.

Thanks a lot for your time Scott!




More information about the Qt-interest-old mailing list