View Full Version : QSqlQueryModel needs filtering data - HOWTO
MarkoSan
16th October 2015, 11:42
I am working on QML/Qt app, which shows some products in QML ListView (named ProductsView), which works fine right now. But I've added second QML ListView (named CategoriesView), which shows product categories and I want to filter ProductsView according to selected category in CategoriesView. Now, in model behind ProductsView I have SQL statement, which selects all products from table. How do I filter ProductsView's model with QSortFilterProxyModel? Is this the right way and how do I filter data inside QSortFilterProxyModel with upgraded SQL statement using WHERE SQL statement?
P.S.: I am aware my questions are maybe confusing, but I do now know how to begin working on this?
Sincerely,
Marko
anda_skoa
16th October 2015, 15:23
You've already mentioned both your options:
1) filter on SQL level by using changing the query of the model that is shown in ProductsView
2) filter in a proxy model that sits between the SQL model and the view.
Either by filtering on a value in one of the columns of the source model or, if a more complex decision is necessary, by deriving and implementing filterAcceptsRow()
I would go for (1)
Cheers,
_
MarkoSan
16th October 2015, 17:45
You've already mentioned both your options:
1) filter on SQL level by using changing the query of the model that is shown in ProductsView
2) filter in a proxy model that sits between the SQL model and the view.
Either by filtering on a value in one of the columns of the source model or, if a more complex decision is necessary, by deriving and implementing filterAcceptsRow()
I would go for (1)
Cheers,
_
Did that, works ok!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.