Results 1 to 5 of 5

Thread: Filtering QSqlQueryModel

  1. #1
    Join Date
    Mar 2008
    Posts
    55
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Filtering QSqlQueryModel

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Italy
    Posts
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Filtering QSqlQueryModel

    Quote Originally Posted by mourad View Post
    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

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Filtering QSqlQueryModel

    Quote Originally Posted by mourad View Post
    Hello everyone, I want to filter QSqlQueryModel.
    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.

  4. #4
    Join Date
    May 2009
    Posts
    28
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Filtering QSqlQueryModel

    sql can do everything !
    you have to just to know what to do + write the good query for that

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Filtering QSqlQueryModel

    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?

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. QComboBox QSqlQueryModel
    By aekilic in forum Qt Programming
    Replies: 8
    Last Post: 17th December 2008, 12:01
  3. QSqlQueryModel fetchMore
    By skuda in forum Qt Programming
    Replies: 0
    Last Post: 17th July 2008, 19:42
  4. QSqlQueryModel speed problem
    By tbscope in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2008, 11:31
  5. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55

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.