[Qt-interest] QSqlTableModel and getting a QModelIndex based ona primary key.
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Mon Sep 26 18:00:45 CEST 2011
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.
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.
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
Scott
-----Original Message-----
From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
[mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
Behalf Of MARTIN Pierre
Sent: Monday, September 26, 2011 6:06 AM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] QSqlTableModel and getting a QModelIndex
based ona primary key.
Oh i forgot. i want to avoid calling setFilter on my model... Because
many views are connected to it, and they should not be filtered by the
logic behind my controller's row retrieval.
> Hello dear list users,
>
> i am asking myself a question before going into implementing something
which could be useless.
> i have a QSqlTableModel-derived model. This class is working on a
table named "Foo", and it sets it's primary key to "id", which is in the
table a classic unique auto-incremented int.
> Now let's say i have a primary key value, and i want the corresponding
QModelIndex from my model... What would be the best way to proceed?
Using fetchMore while canFetchMore and then iterate thru all records?
>
> Is there anything usable in the existing implementations of
QSqlQueryModel / QSqlTableModel?
>
> Thank you,
> Pierre.
>
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list