diff options
author | Alexander Volkov <a.volkov@rusbitech.ru> | 2016-05-25 14:05:55 +0300 |
---|---|---|
committer | Alexander Volkov <a.volkov@rusbitech.ru> | 2016-09-05 15:55:11 +0000 |
commit | 6b7c1f5b82246146df0eb25950956307b64b0945 (patch) | |
tree | 1b408835fabe942139fd947275988cb9398610b0 /src/corelib/io/qtemporarydir.cpp | |
parent | 590ca436032cb828fc882fde9c0e99e0f450a061 (diff) |
Add a convenience function QTemporaryDir::filePath()
It allows to write more readable code:
QString filePath = tmpDir.filePath(fileName);
instead of
QString filePath = tmpDir.path() + QLatin1Char('/') + fileName;
Change-Id: I85aa54fd365e3bdd3ca41018ead7ed8741352b16
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/io/qtemporarydir.cpp')
-rw-r--r-- | src/corelib/io/qtemporarydir.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/corelib/io/qtemporarydir.cpp b/src/corelib/io/qtemporarydir.cpp index 6e50a8513e..d116d00bb9 100644 --- a/src/corelib/io/qtemporarydir.cpp +++ b/src/corelib/io/qtemporarydir.cpp @@ -305,6 +305,33 @@ QString QTemporaryDir::path() const } /*! + \since 5.8 + + Returns the path name of a file in the temporary directory. + Does \e not check if the file actually exists in the directory. + Redundant multiple separators or "." and ".." directories in + \a fileName are not removed (see QDir::cleanPath()). Absolute + paths are not allowed. +*/ +QString QTemporaryDir::filePath(const QString &fileName) const +{ + if (QDir::isAbsolutePath(fileName)) { + qWarning("QTemporaryDir::filePath: Absolute paths are not allowed: %s", qUtf8Printable(fileName)); + return QString(); + } + + if (!d_ptr->success) + return QString(); + + QString ret = d_ptr->pathOrError; + if (!fileName.isEmpty()) { + ret += QLatin1Char('/'); + ret += fileName; + } + return ret; +} + +/*! Returns \c true if the QTemporaryDir is in auto remove mode. Auto-remove mode will automatically delete the directory from disk upon destruction. This makes it very easy to create your |