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

Henry Skoglund fromqt at tungware.se
Sat May 11 23:22:23 CEST 2019

On 2019-05-11 21:13, Alexander Dyagilev 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.

Hi, unless you're changing chars in the filename to uppercase/lowercase, 
where I know QFile tries to help on case-insensitive filesystems, 
QFile/QDir is pretty much at the mercy of the OS, i.e. if the OS refuses 
the renaming (for example on NTFS when you try to rename across volumes) 
then QFile dutifully copies the file instead.

So I think this is not a Qt question and you need to drop down to the OS 
level, for example on Windows you can call ::MoveFileEx() with the 3rd 
param = 0, then the call will err out if a copy is needed.
(Note: I haven't tested this myself, just relying on Google :-)

Rgrds Henry

More information about the Interest mailing list