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.
Code:
// Find button pressed
QString searchValue
= ui
->keywordLineEdit
->text
();
QString searchField
= ui
->fromComboBox
->currentText
();
QString searchFilter
= searchField
+ "=" + searchValue;
qDebug() << "Searching for " << searchValue << "from" << ui->fromComboBox->currentIndex() << "!!!";
if (!searchValue.isEmpty()) {
model->setTable("Products");
model->select();
filterModel1->setSourceModel(model);
filterModel1->setFilterRegExp(searchValue);
filterModel1->setFilterKeyColumn(ui->fromComboBox->currentIndex());
filterModel1->setFilterCaseSensitivity(Qt::CaseInsensitive);
ui->tableView->setModel(filterModel1);
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
Re: Problem with QSortFilterProxyModel
Quote:
Originally Posted by
pcheng
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.