Sort and Filter a QSqlQueryModel

From Qt Wiki
Revision as of 17:48, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Sort and Filter a QSqlQueryModel

QSortFilterSqlQueryModel is a QSqlQueryModel subclass that allows server-side sorting and filtering.

Feel free to download and test it.

Example usage

You can connect a QLineEdit’s textChanged signal to the filter slot:
filter is the same as setFilter, but it also call select();

Sorting is done automatically by the view, using the sort implementation. You can also use setSort to set a sort order before select()ing.

Warnings

  • It has only been tested in Windows using MySQL
  • It won’t work using setQuery(QSqlQuery). I didn’t needed it so you have to reimplement it yourself.
  • Works for me. May not work for you. :P

Code

QSortFilterSqlQueryModel.h

QSortFilterSqlQueryModel.cpp

Categories: