Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 C++/Qt 将文件从一个位置复制到另一个位置(在设备中)
我试过 QFile::copy("path1/file","path2");
我想将path1中的文件复制到path2。path2 没有该文件。
我只是想知道这是否是正确的方法,因为上面的代码似乎不起作用。
另外,我应该在尝试复制之前打开文件吗?需要帮忙!
如果您想使用相同的文件名复制path1/file到path2,您需要执行以下操作:
path1/file
path2
QFile::copy("path1/file", "path2/file");
复制允许您更改文件的名称。例子:
QFile::copy("path1/file1", "path1/file2");
这就是为什么您需要两次都包含文件名的原因。此外,不必先打开文件。为了回答标题问题,它复制了文件。QFile::rename()移动内容。
QFile::rename()