如何在qt中将文件从源目录复制到目标目录

如何在qt中将文件从源目录复制到目标目录,qt,Qt,我必须将文件从源目录复制到目标目录。您能提供执行此类操作的代码吗?我想要类似的东西,但在谷歌上搜索(徒劳),因此我必须: static bool cpDir(const QString &srcPath, const QString &dstPath) { rmDir(dstPath); QDir parentDstDir(QFileInfo(dstPath).path()); if (!parentDstDir.mkdi

我必须将文件从源目录复制到目标目录。您能提供执行此类操作的代码吗?

我想要类似的东西,但在谷歌上搜索(徒劳),因此我必须:

 static bool cpDir(const QString &srcPath, const QString &dstPath)
    {
        rmDir(dstPath);
        QDir parentDstDir(QFileInfo(dstPath).path());
        if (!parentDstDir.mkdir(QFileInfo(dstPath).fileName()))
            return false;

        QDir srcDir(srcPath);
        foreach(const QFileInfo &info, srcDir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) {
            QString srcItemPath = srcPath + "/" + info.fileName();
            QString dstItemPath = dstPath + "/" + info.fileName();
            if (info.isDir()) {
                if (!cpDir(srcItemPath, dstItemPath)) {
                    return false;
                }
            } else if (info.isFile()) {
                if (!QFile::copy(srcItemPath, dstItemPath)) {
                    return false;
                }
            } else {
                qDebug() << "Unhandled item" << info.filePath() << "in cpDir";
            }
        }
        return true;
    }
static bool cpDir(常量QString&srcPath,常量QString&dstPath)
{
rmDir(dstPath);
QDir parentDstDir(QFileInfo(dstPath.path());
if(!parentDstDir.mkdir(QFileInfo(dstPath.fileName()))
返回false;
QDir srcDir(srcPath);
foreach(const QFileInfo&info,srcDir.entryinfo列表(QDir::Dirs | QDir::Files | QDir::nodotanddot)){
QString srcItemPath=srcPath+“/”+info.fileName();
QString dstItemPath=dstPath+“/”+info.fileName();
if(info.isDir()){
如果(!cpDir(srcItemPath,dstItemPath)){
返回false;
}
}else if(info.isFile()){
if(!QFile::copy(srcItemPath,dstItemPath)){
返回false;
}
}否则{

qDebug()我相信这篇文章已经回答了这个问题:对于Qt,你是说qmake?