3

In my qt application each time my program loads I copy the latest version of some files. I noticed that QFile::copy() does not seem to allow this. In the Qt docs it says:

Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it).

I know I can probably do something simple like:

if (QFile::exists(targetFile))
{
    QFile::remove(targetFile);
}
QFile::copy(sourceFile, targetFile);

But I am wandering if there is some clever Qt way of doing this... there usually is and I often end up not taking advantage of many Qt features because I just don't know about them.

code_fodder
  • 15,263
  • 17
  • 90
  • 167
  • 3
    Possible duplicate of [Copy file even when destination exists (in Qt)](http://stackoverflow.com/questions/14935919/copy-file-even-when-destination-exists-in-qt) – demonplus Mar 24 '16 at 07:49
  • There is no such option for QFile – demonplus Mar 24 '16 at 07:51
  • @demonplus Maybe.. but I am really only asking if there is a Qt way of doing it. I don't want to create my own library function (though it is a simple one) if can avoid it. It was not stated categorically that nothing in Qt does not allow you to do this - and this is what my question is. All the "answers" in that question are to delete first... – code_fodder Mar 24 '16 at 08:07
  • I don't think there's an atomic operation you can use to accomplish this with existing Qt classes. – quinz Mar 24 '16 at 09:19

0 Answers0