PDA

View Full Version : Filtering QSqlQueryModel



mourad
27th May 2009, 16:35
Hello everyone, I want to filter QSqlQueryModel. I've used QSortFilterProxyModel but I have many fields to filter on. All depends on the user criteria.
I have a look on the Qt documentation but I've not found anything that helps me.
Can anyone help me to resolve this problem.
Many thanks in advance.
Best Regards.

Zuzzu
1st June 2009, 01:56
Hello everyone, I want to filter QSqlQueryModel. I've used QSortFilterProxyModel but I have many fields to filter on. All depends on the user criteria.
I have a look on the Qt documentation but I've not found anything that helps me.
Can anyone help me to resolve this problem.
Many thanks in advance.
Best Regards.

Hi,

one of the possibility is to use more than one QSortFilterProxyModel to filter you data. This approach can be applied if the filter criteria is like "ColumnA = 'ValueA' AND ColumnB = 'ValueB' ....).

If the filtering criteria is more complex, you can make a subclass of QSortFitlerProxyModel and reimplement the filterAcceptRow method in order to implement your specific filter criteria.

Bye.

Alessandro

Lykurg
1st June 2009, 10:07
Hello everyone, I want to filter QSqlQueryModel.

:confused: How that, is the WHERE, GROUP BY clauses of your MySQL statement not enough? You can set new queries on the model, if your user criterias change. That would be the easiest approach.

QAmazigh
1st June 2009, 14:16
sql can do everything !
you have to just to know what to do + write the good query for that :)

ChrisW67
2nd August 2009, 10:32
Building an SQL Where clause does work but if you go changing the filter query on a QSQlTableModel then you have to run select(), which invalidate your model, clears any associated selections, and reset the views losing the current position. Is there any way to avoid this?