[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

https://code.woboq.org/qt5/qtbase/src/corelib/io/qfile.cpp.html

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

The class can be found here:

https://code.woboq.org/qt5/qtbase/src/corelib/io/qfilesystemengine_p.h.html#QFileSystemEngine

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)) {
             unsetError();
             // engine was able to handle the new name so we just reset it
             d->fileEngine->setFileName(newName);
             d->fileName = newName;
             return true;
}

That will be a bit more involved though.

-- 

Roland Hughes, President
Logikal Solutions
(630)-205-1593  (cell)
http://www.theminimumyouneedtoknow.com
http://www.infiniteexposure.net
http://www.johnsmith-book.com




More information about the Interest mailing list