summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2017-05-09 12:43:43 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2017-05-16 06:00:47 +0000
commitd0a1135f00f21a8d1bbe21391a56fac7cb820d36 (patch)
tree9321e54846a21384b90f4dd8a726aa3fc83f3dde /src/corelib
parent7da9fa289068ed742307c6b921442365130e0818 (diff)
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>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp9
-rw-r--r--src/corelib/io/qdiriterator.cpp4
2 files changed, 13 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp
index 7a6ffeae06..31442a5516 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qdiriterator.cpp
@@ -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]
diff --git a/src/corelib/io/qdiriterator.cpp b/src/corelib/io/qdiriterator.cpp
index b1d920c6ee..648593b020 100644
--- a/src/corelib/io/qdiriterator.cpp
+++ b/src/corelib/io/qdiriterator.cpp
@@ -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