solotim
21st August 2012, 11:32
Hi, I found that QSortFilterProxyModel can't filter properly when it works with QFileSystemModel. Sometimes it left NOTHING in the view. Can anyone point out where I'm wrong?
Just create a simple GUI example:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFileSystemModel *fsm = new QFileSystemModel(this);
fsm->setRootPath(".");
QSortFilterProxyModel *sfpm = new QSortFilterProxyModel();
sfpm->setDynamicSortFilter(true);
sfpm->setSourceModel(fsm);
sfpm->setFilterRegExp(QRegExp(".cpp", Qt::CaseInsensitive,
QRegExp::FixedString));
sfpm->setFilterKeyColumn(0);
ui->tableView->setModel(sfpm);
ui->tableView->setRootIndex(sfpm->mapFromSource(fsm->index(".")));
}
if you comment out the setFilterRegExp statement, sure the files in current path are shown in the view. I've also tried setFilterWildcard and other RegExp, nothing works. Very frustrating.
Just create a simple GUI example:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFileSystemModel *fsm = new QFileSystemModel(this);
fsm->setRootPath(".");
QSortFilterProxyModel *sfpm = new QSortFilterProxyModel();
sfpm->setDynamicSortFilter(true);
sfpm->setSourceModel(fsm);
sfpm->setFilterRegExp(QRegExp(".cpp", Qt::CaseInsensitive,
QRegExp::FixedString));
sfpm->setFilterKeyColumn(0);
ui->tableView->setModel(sfpm);
ui->tableView->setRootIndex(sfpm->mapFromSource(fsm->index(".")));
}
if you comment out the setFilterRegExp statement, sure the files in current path are shown in the view. I've also tried setFilterWildcard and other RegExp, nothing works. Very frustrating.