[Interest] QFile/QDir: force move mode only?

Roland Hughes roland at logikalsolutions.com
Sun May 12 16:00:01 CEST 2019

On 5/12/19 5:00 AM, interest-request at qt-project.org wrote:
> Hello,
> QFile/QDir rename function copies file in the case it's not possible to
> just move it.
> Is there a  way to learn in advance what type of operation will occur?
> Let's suppose I have 10GB file. In case of copy, I would definitely like
> to use my own copy function and show UI with the progress of the operation.
> And of course I do not want to use my copy function always if the fast
> move is available.

You need to use a different class. Look around line 615 here


             // rename to final name
             if (QFileSystemEngine::renameFile(tmp, 
QFileSystemEntry(newName), error)) {
                 d->fileName = newName;
                 return true;

The class can be found here:


That's how you can catch the rename failure then do your own thing on 
copy. Be sure to read the comments in the file. If you will never be 
"just changing case" of a file name and can control that, then only that 
snippet should apply to you.

You might want to add a conditional compile and use part of this snippet 
from around line 643 for the lesser platforms.

         if (changingCase ? d->engine()->renameOverwrite(newName) : 
d->engine()->rename(newName)) {
             // engine was able to handle the new name so we just reset it
             d->fileName = newName;
             return true;

That will be a bit more involved though.


Roland Hughes, President
Logikal Solutions
(630)-205-1593  (cell)

More information about the Interest mailing list