PDA

View Full Version : QRegExp on QSortFilterProxyModel



Nightfox
17th February 2010, 20:39
I'm trying to filter out items from a soruce model (model) with the following values in the FilterKeyColumn;
BALA,DRIF,120,5000

I want to filter out the BALA row using QRegExp leaving the model with three items. I've tried using the following regular expression but it either retruns all four rows or no rows



QSortFilterProxyModel *filterproxy = new QSortFilterProxyModel(this);
filterproxy->setSourceModel(model);
filterproxy->setFilterKeyColumn(1);
filterproxy->setFilterRegExp(QRegExp("(?!bala)",Qt::CaseInsensitive,QRegExp::FixedString) );
tableview->setModel(proxymodel);

Basically what I want to do is to show all rows in the model except the row that has "bala" value in the FilterKeyColumn. The Qt Assistant is not really clear about negative expressions or how to apply a NOT validator.

Can somebody help?

Lykurg
17th February 2010, 21:17
I guess you don't want to use QRegExp::FixedString. Try QRegExp::RegExp or QRegExp::RegExp2.

Nightfox
17th February 2010, 22:14
Hi Lykurg

Thank you for replying.

Changing the pattern syntax doesn't help. When using "bala" instead instead of "(?!bala)" only one row is accepted. This is exactly what I'm looking for - only opposite. Does RegExp contain a NOT keyword or symbol like !"bala"? It's not clear from the QSortFilterProxyModel class description nor the QRegExp description