Results 1 to 2 of 2

Thread: Problem with QSortFilterProxyModel

  1. #1
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QSortFilterProxyModel

    I am trying to get a QSortFilterProxyModel to filter a table based on two inputs. The first input is a string that can have wildcards in it while the second one is a dropdown which shows the names of all the columns in the table.

    When the user enters a string in the first input and selects a column I call the model and set the QSortFilterProxyModel in the way shown below.

    Qt Code:
    1. // Find button pressed
    2. QString searchValue = ui->keywordLineEdit->text();
    3. QString searchField = ui->fromComboBox->currentText();
    4. QString searchFilter = searchField + "=" + searchValue;
    5. qDebug() << "Searching for " << searchValue << "from" << ui->fromComboBox->currentIndex() << "!!!";
    6. if (!searchValue.isEmpty()) {
    7. model = new QSqlRelationalTableModel(this);
    8. model->setTable("Products");
    9. model->select();
    10.  
    11. filterModel1->setSourceModel(model);
    12. filterModel1->setFilterRegExp(searchValue);
    13. filterModel1->setFilterKeyColumn(ui->fromComboBox->currentIndex());
    14. filterModel1->setFilterCaseSensitivity(Qt::CaseInsensitive);
    15.  
    16. ui->tableView->setModel(filterModel1);
    To copy to clipboard, switch view to plain text mode 

    This does not seem to show anything in the tableview. Could anyone help me by identifying what I am missing?

    Thanks,

    Pericles


    Added after 19 minutes:


    It seems that every time I ask a question the solution comes to me immediately afterwards.

    I am sorry for posting questions and answering them a few minutes later. It seems that I need to trust myself to find the answer a little longer.

    I solved this by changing the
    filterModel1->setFilterRegExp(searchValue);
    to
    filterModel1->setFilterRegExp(QRegExp(searchValue, Qt::CaseInsensitive, QRegExp::FixedString));

    This seemed to do the trick even though I think I tried this before but something else must have been the problem.

    Thanks and sorry for the redundant post.

    Pericles
    Last edited by pcheng; 18th June 2012 at 09:55.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QSortFilterProxyModel

    Quote Originally Posted by pcheng View Post
    It seems that every time I ask a question the solution comes to me immediately afterwards.

    I am sorry for posting questions and answering them a few minutes later. It seems that I need to trust myself to find the answer a little longer.
    That's not a problem. Sometimes it is important to write a simple definition of a problem, step back and look at it to find a solution. It's great that you managed to find the solution on your own, don't be sorry for that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 9th March 2011, 00:08
  2. Replies: 0
    Last Post: 8th March 2011, 12:58
  3. Subclassing QSortFilterProxyModel problem
    By e79ene in forum Newbie
    Replies: 2
    Last Post: 21st February 2011, 13:23
  4. Problem QSortFilterProxyModel
    By estanisgeyer in forum Qt Programming
    Replies: 3
    Last Post: 15th June 2009, 18:51
  5. QSortFilterProxyModel problem
    By blukske in forum Qt Programming
    Replies: 8
    Last Post: 22nd June 2006, 08:26

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.