Results 1 to 3 of 3

Thread: QSqlQueryModel needs filtering data - HOWTO

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question QSqlQueryModel needs filtering data - HOWTO

    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
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel needs filtering data - HOWTO

    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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    MarkoSan (16th October 2015)

  4. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSqlQueryModel needs filtering data - HOWTO

    Quote Originally Posted by anda_skoa View Post
    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!
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Sorting and filtering sql data
    By kode in forum Newbie
    Replies: 2
    Last Post: 12th June 2013, 04:11
  2. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  3. Reimplement data() in QSqlQueryModel
    By john_erlandsson in forum Newbie
    Replies: 3
    Last Post: 5th January 2012, 03:36
  4. Filtering QSqlQueryModel
    By mourad in forum Qt Programming
    Replies: 4
    Last Post: 2nd August 2009, 09:32
  5. Different data types in a QSqlQueryModel
    By Lodas in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2008, 16:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.