1. 文件拷贝
bool copy(const QString &newName);
static bool copy(const QString &fileName, const QString &newName);
Copies the file fileName to newName.
示例代码
//构造文件路径
QString fileName = "config.json";
QString oldFolderPath = QDir::currentPath();//文件所在的当前目录
QString oldFilePath = oldFolderPath+"/"+fileName;
QString newFolderPath = oldFolderPath + "/snapshot"; //要拷贝到的新目录
QString newFilePath = newFolderPath+"/"+ fileName;
// 如果新文件夹路径不存在,则创建
QDir dir;
dir.mkdir(newFolderPath);
// 拷贝文件
QFile::copy(oldFilePath, newFilePath);