QDirIterator docs: add a cool recursive file-finding snippet

This is one of the main use cases for QDirIterator, but it wasn't
obvious enough that it's possible.

Change-Id: Idae11cfe75dd0e16f1a960bba2470b1695d11241
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
This commit is contained in:
Shawn Rutledge 2017-05-09 12:43:43 +02:00
parent 7da9fa2890
commit d0a1135f00
2 changed files with 13 additions and 0 deletions

View File

@ -60,3 +60,12 @@ while (it.hasNext()) {
// ...
}
//! [0]
//! [1]
QDirIterator it("/sys", QStringList() << "scaling_cur_freq", QDir::NoFilter, QDirIterator::Subdirectories);
while (it.hasNext()) {
QFile f(it.next());
f.open(QIODevice::ReadOnly);
qDebug() << f.fileName() << f.readAll().trimmed().toDouble() / 1000 << "MHz";
}
//! [1]

View File

@ -56,6 +56,10 @@
\snippet code/src_corelib_io_qdiriterator.cpp 0
Here's how to find and read all files filtered by name, recursively:
\snippet code/src_corelib_io_qdiriterator.cpp 1
The next() function returns the path to the next directory entry and
advances the iterator. You can also call filePath() to get the current
file path without advancing the iterator. The fileName() function returns