Results 1 to 6 of 6

Thread: trouble with QSqlRelationalTableModel and setFilter

  1. #1
    Join Date
    Jul 2008
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Smile trouble with QSqlRelationalTableModel and setFilter

    I use QSqlRelationalTableModel with QTableView .when I setFilter to the QSqlRelationalTableModel ,it does not work ,and no data was displayed in the tabview.
    please help me,thanks..

  2. #2
    Join Date
    Jul 2008
    Location
    Spain
    Posts
    23
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: trouble with QSqlRelationalTableModel and setFilter

    Perhaps your filter criteria is incorrect.

    I use QSqlRelationalTableModel on Qt 4.3 with PostgreSQL 8.3.3.

    To filter numeric values I use comparison operators (=, <, >, >=, <=).
    To filter strings I use "LIKE" (case sensitive) or "ILIKE" (case insensitive, only for PostgreSQL) and the wildcard %.

    Examples:
    Qt Code:
    1. my_model.setFilter("my_table.my_numeric_field > 162");
    2. my_model.setFilter("my_table.my_numeric_field = 162");
    3. my_model.setFilter("my_table.my_text_field ILIKE '%substring%'");
    4. my_model.setFilter("my_table.my_text_field ILIKE 'begin_string%'");
    5. my_model.setFilter("my_table.my_text_field ILIKE '%end_string'");
    To copy to clipboard, switch view to plain text mode 

    If I am wrong, please, send more information about your problem.
    Auryn
    Starting to learn the world of Qt

  3. #3
    Join Date
    Jul 2008
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: trouble with QSqlRelationalTableModel and setFilter

    thanks for replying.
    I mean than the setRelation and setFilter can not work together.
    when I set both ,it does not work ,but anyone of the two can work alone.
    the code:
    Qt Code:
    1. m_Modle->setTable(tabName);
    2. m_Modle->setFilter(fiterstring);
    3. m_Modle->setRelation(1,QSqlRelation(reTabName,reFieldName,reDisName));
    4.  
    5. m_Modle->select();
    6. m_pShowTree->setModel(m_Modle);
    To copy to clipboard, switch view to plain text mode 

    then no data was outputted;
    Last edited by jpn; 31st July 2008 at 21:39. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2008
    Posts
    4

    Default Re: trouble with QSqlRelationalTableModel and setFilter

    Has anybody solved this problem?

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: trouble with QSqlRelationalTableModel and setFilter

    What is in : tabName, fiterstring, reTabName, reFieldName and reDisName ?
    I'm asking because in my code all is working perfect.

  6. #6
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: trouble with QSqlRelationalTableModel and setFilter

    Try an absolute path (tableName.columnName syntax) in your Filter clause. E.g.

    model->setFilter("blah.id = 1")
    vs.
    model->setFilter("id = 1")

    If you look at the resultant SQL statement you'll notice that a join on two or more tables is performed when you use a QSqlRelationTableModel, therefore there could be multiple fields with the same name (particularly if your column is named something like id).

  7. The following 3 users say thank you to bmn for this useful post:

    Alir3z4 (12th July 2011), D Cell (27th February 2010), rivci (3rd January 2011)

Similar Threads

  1. Replies: 11
    Last Post: 10th July 2007, 15:58
  2. QDataTable setFilter
    By cristiano in forum Qt Programming
    Replies: 10
    Last Post: 17th November 2006, 01:38

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.