summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Di Sera <luca.disera@qt.io>2021-08-24 09:27:19 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-28 07:41:40 +0000
commit8566dfdb63dacb7f613c3745ee4eaed11f16020e (patch)
tree51aef784814f769067a1c7cd45aebc9d1abfc04c
parent4cbcdf62bdaf7679457fe6609f70a36c29497530 (diff)
Doc: Replace the example for QFileInfo::setFile
The example in the documentation of `QFileInfo::setFile` made no use of `setFile` and only showed a use of `QDir::setCurrent`. The example was replaced with a new example showing how `setFile` changes the file that the information are retrieved from. The old example was moved under the documentation for `QDir::setCurrent` as it shows its working. Fixes: QTBUG-87128 Change-Id: I8227876cfcb4d582040bda9b4b7f3f7debea1e07 Reviewed-by: Paul Wicking <paul.wicking@qt.io> (cherry picked from commit a2abb0145174a8ed82572a06e537f550a6777b08) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp13
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp17
-rw-r--r--src/corelib/io/qdir.cpp2
3 files changed, 22 insertions, 10 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp
index 4e5e25a64a..3b9435f022 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qdir.cpp
@@ -182,4 +182,17 @@ namespace MyNamespace
Q_CLEANUP_RESOURCE(myapp);
//! [15]
+//! [16]
+QString absolute = "/local/bin";
+QString relative = "local/bin";
+QFileInfo absFile(absolute);
+QFileInfo relFile(relative);
+
+QDir::setCurrent(QDir::rootPath());
+// absFile and relFile now point to the same file
+
+QDir::setCurrent("/tmp");
+// absFile now points to "/local/bin",
+// while relFile points to "/tmp/local/bin"
+//! [16]
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp
index 036625370e..d81360ee5b 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp
@@ -90,19 +90,16 @@ info2.size(); // returns 63942
//! [2]
-QString absolute = "/local/bin";
-QString relative = "local/bin";
-QFileInfo absFile(absolute);
-QFileInfo relFile(relative);
+QFileInfo info("/usr/bin/env");
-QDir::setCurrent(QDir::rootPath());
-// absFile and relFile now point to the same file
+QString path = info.absolutePath(); // path = /usr/bin
+QString base = info.baseName(); // base = env
-QDir::setCurrent("/tmp");
-// absFile now points to "/local/bin",
-// while relFile points to "/tmp/local/bin"
-//! [2]
+info.setFile("/etc/hosts");
+path = info.absolutePath(); // path = /etc
+base = info.baseName(); // base = hosts
+//! [2]
//! [3]
QFileInfo fi("/tmp/archive.tar.gz");
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 8452e3d324..6687ecb2b9 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -2011,6 +2011,8 @@ QChar QDir::separator()
Returns \c true if the directory was successfully changed; otherwise
returns \c false.
+ \snippet code/src_corelib_io_qdir.cpp 16
+
\sa current(), currentPath(), home(), root(), temp()
*/
bool QDir::setCurrent(const QString &path)