Ashish
Ashish

Reputation: 249

find(Search) particular named file from QFilesystemmodel

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.

Upvotes: 0

Views: 1227

Answers (1)

Pavel Strakhov
Pavel Strakhov

Reputation: 40502

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.

Upvotes: 1

Related Questions