Will QFile::copy create create a copy of the file or move the contents from one file to another?

19,041

If you want to copy path1/file into path2 with the same file name, you'll want to do:

QFile::copy("path1/file", "path2/file");

Copy allows you to change the name of the file. Example:

QFile::copy("path1/file1", "path1/file2");

Which is why you need to include the file name both times. Also, it is not necessary to open the file first. And to answer the title question, it copies the file. QFile::rename() moves the contents.

Share:
19,041
user1065969
Author by

user1065969

Updated on June 07, 2022

Comments

  • user1065969
    user1065969 about 2 years

    I am trying to copy a file from one location to another( in a device) using C++/Qt

    I tried QFile::copy("path1/file","path2");

    I want to copy the file in path1 to path2. path2 does not have the file.

    I just want to know if this is the right way because the above code does not seem to work.

    Also, should I do a file open before I try to copy? Need help!