Мне нужно показать QTreeView определенного каталога, и я хочу дать пользователю возможность фильтровать файлы с помощью RegExp.
Как я понимаю, в документации Qt я могу добиться этого с помощью упомянутых классовв заголовке вот так:
// Create the Models
QFileSystemModel *fileSystemModel = new QFileSystemModel(this);
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
// Set the Root Path
QModelIndex rootModelIndex = fileSystemModel->setRootPath("E:\\example");
// Assign the Model to the Proxy and the Proxy to the View
proxyModel->setSourceModel(fileSystemModel);
ui->fileSystemView->setModel(proxyModel);
// Fix the TreeView on the Root Path of the Model
ui->fileSystemView->setRootIndex(proxyModel->mapFromSource(rootModelIndex));
// Set the RegExp when the user enters it
connect(ui->nameFilterLineEdit, SIGNAL(textChanged(QString)),
proxyModel, SLOT(setFilterRegExp(QString)));
При запуске программы TreeView корректно фиксируется в указанном каталоге.Но как только пользователь меняет RegExp, создается впечатление, что TreeView забывает свой RootIndex.После удаления всего текста в RegExp LineEdit (или ввода RegExp наподобие «.») Он снова показывает все каталоги (в Windows это означает все диски и т. Д.)
Что я делаю не так?: /