PDA

View Full Version : how to limit sql rows



calhal
30th July 2008, 12:28
Hi,
Anyone knows how to limit number of rows shown in QTreeView with QSqlTableModel (or QSortFilterProxy) to some number (given by user)?

triperzonak
30th July 2008, 14:22
Hi,
Anyone knows how to limit number of rows shown in QTreeView with QSqlTableModel (or QSortFilterProxy) to some number (given by user)?

in my case im adding LIMIT to setfilter() (http://http://doc.trolltech.com/4.4/qsqltablemodel.html#setFilter)
note: you cannot directly add LIMIT to filter like setfileter("LIMIT 10"), adding Where clause will do the trick setfilter("Where yourdata not null LIMIT 10")..

thats my quick solution.

calhal
31st July 2008, 07:25
Thanks for your response. But it doesn't work for me. I get no rows at all when I add LIMIT to the filter.

Cyberman
30th December 2009, 10:17
Hi all!

I think this happens because QSqlTableModel will call setSort after setFilter and this produces an Error (the LIMIT clause must be after any sorting clauses).

As far as I know, the only solutions are:


Use QSqlQueryModel
Subclass QSqlTableModel and implement the function (e.g implement the setQuery function)


I hope this can help.