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>
This commit is contained in:
Luca Di Sera 2021-08-24 09:27:19 +02:00 committed by Qt Cherry-pick Bot
parent f906f1d1ce
commit eddf2adb29
3 changed files with 22 additions and 10 deletions

View File

@ -182,4 +182,17 @@ namespace MyNamespace
Q_CLEANUP_RESOURCE(myapp); Q_CLEANUP_RESOURCE(myapp);
//! [15] //! [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]
} }

View File

@ -90,20 +90,17 @@ info2.size(); // returns 63942
//! [2] //! [2]
QString absolute = "/local/bin"; QFileInfo info("/usr/bin/env");
QString relative = "local/bin";
QFileInfo absFile(absolute);
QFileInfo relFile(relative);
QDir::setCurrent(QDir::rootPath()); QString path = info.absolutePath(); // path = /usr/bin
// absFile and relFile now point to the same file QString base = info.baseName(); // base = env
QDir::setCurrent("/tmp"); info.setFile("/etc/hosts");
// absFile now points to "/local/bin",
// while relFile points to "/tmp/local/bin" path = info.absolutePath(); // path = /etc
base = info.baseName(); // base = hosts
//! [2] //! [2]
//! [3] //! [3]
QFileInfo fi("/tmp/archive.tar.gz"); QFileInfo fi("/tmp/archive.tar.gz");
QString name = fi.fileName(); // name = "archive.tar.gz" QString name = fi.fileName(); // name = "archive.tar.gz"

View File

@ -1951,6 +1951,8 @@ QFileInfoList QDir::drives()
Returns \c true if the directory was successfully changed; otherwise Returns \c true if the directory was successfully changed; otherwise
returns \c false. returns \c false.
\snippet code/src_corelib_io_qdir.cpp 16
\sa current(), currentPath(), home(), root(), temp() \sa current(), currentPath(), home(), root(), temp()
*/ */
bool QDir::setCurrent(const QString &path) bool QDir::setCurrent(const QString &path)