1

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.

Core Xii
  • 6,270
  • 4
  • 31
  • 42
developer
  • 37
  • 1
  • 6
  • You should try to rewrite that question, I'm not sure what you are asking. Are you just looking for [QSqlTableModel](http://qt-project.org/doc/qt-4.8/qsqltablemodel.html) ? It's in the doc along with [other Qt Sql classes](http://qt-project.org/doc/qt-4.8/qtsql.html) such as QSqlRelationalTableModel. – Leiaz Nov 22 '12 at 11:48
  • My question is that I get data from sqlite and write them to model and when i searching any data for exp someone's name i dont want write sql command i wanna find them using my model – developer Nov 23 '12 at 06:20

2 Answers2

1

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.

Leiaz
  • 2,867
  • 2
  • 20
  • 23
0
  1. No, QtSQL module doesn't provide any ORM, so you have to write SQL queries on your own.

  2. 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.

hate-engine
  • 2,300
  • 18
  • 26