diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 1dedc7c5c8..23bf3c5f4b 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -1741,11 +1741,16 @@ bool QDir::remove(const QString &fileName) true if successful; otherwise returns false. On most file systems, rename() fails only if \a oldName does not - exist, if \a newName and \a oldName are not on the same - partition or if a file with the new name already exists. + exist, or if a file with the new name already exists. However, there are also other reasons why rename() can fail. For example, on at least one file system rename() fails if \a newName points to an open file. + + If \a oldName is a file (not a directory) that can't be renamed + right away, Qt will try to copy \a oldName to \a newName and remove + \a oldName. + + \sa QFile::rename() */ bool QDir::rename(const QString &oldName, const QString &newName) { diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 6640dca70b..6e7b39fcf4 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -698,6 +698,11 @@ QFile::remove(const QString &fileName) The file is closed before it is renamed. + If the rename operation fails, Qt will attempt to copy this file's + contents to \a newName, and then remove this file, keeping only + \a newName. If that copy operation fails or this file can't be removed, + the destination file \a newName is removed to restore the old state. + \sa setFileName() */