I am newbie in Qt. I am using QFileSystemModel in QTreeview to explore the contents of the drives. I want to find a particular named file from anyone drive using this QFileSystemModel. Now, Is there any way to find that particular file from this model ? Thanks in advance.
Asked
Active
Viewed 1,041 times
1 Answers
1
QFileSystemModel
doesn't provide any search methods. You should use QDirIterator instead.
QString find_file(QString dir, QString name) {
QDirIterator it(dir, QDirIterator::Subdirectories);
while (it.hasNext()) {
it.next();
if (it.fileName() == name) {
return it.filePath();
}
}
return QString();
}
You can use QFileSystemModel::index
method to convert file path to model index.

Pavel Strakhov
- 39,123
- 5
- 88
- 127