Reputation: 37
I have my own QAbstractTableModel
connected to SQLite. I get data from database and write it to my list by column name. I don't want handle to my table by SQL query when I'm looking for data.
What do you think about? Is it normal?
Please give me some advice.
Upvotes: 1
Views: 357
Reputation: 2350
No, QtSQL module doesn't provide any ORM, so you have to write SQL queries on your own.
However, you can use QSortFilterProxyModel (or subclass it, or even put filtering code in your subclass of QAbstractTableModel
) for searching/filtering. But I advise you not to do so, because relational databases may (and with high probability will) optimize your search.
Upvotes: 0
Reputation: 2917
To search the data in a model you can use QSortFilterProxyModel. You set your model as source model for the proxy model, and display the proxy model in a "search results" view.
You can use setFilterRegExp()
and setFilterKeyColumn()
to specify for instance the name you are looking for and your "name" column. You can also subclass it if you want more complex filtering. There is an example in the doc.
Upvotes: 1