Reputation: 33823
I'm use QTreeView
with setFilter()
function to allow to display the directories and drivers only but files does not allowed.
But I want to get the files that don't appear in QTreeView
, with continue display the directories and drivers only without files in QTreeView
.
QFileSystemModel dirsModel = new QFileSystemModel;
dirsModel->setRootPath("");
ui->treeView->setModel(dirsModel);
dirsModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
How can I do that ?
Upvotes: 1
Views: 107
Reputation: 18524
As I said earlier you need to get entryList
. For example:
void MainWindow::on_pushButton_clicked()
{
QModelIndex ind = ui->treeView->currentIndex();
QFileSystemModel *sys = qobject_cast<QFileSystemModel*>( ui->treeView->model());
QString path = sys->filePath(ind);
qDebug() << path;
QDir dir(path);
QStringList files = dir.entryList(QStringList(), QDir::Files);
if(!files.size())
qDebug()<< "Empty";
else
for(int i=0 ; i<files.size();i++)
qDebug() << files.at(i);
}
We used QFileSystemModel
here only to get current path, entryList
is absolutely separate from this.
Upvotes: 1