即使目标存在时也复制文件(在Qt中) [英] Copy file even when destination exists (in Qt)

查看:200
本文介绍了即使目标存在时也复制文件(在Qt中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QFile :: copy 文档中,它表示


如果名称为newName的文件已存在,copy()将返回false
(即,QFile不会覆盖它)。

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

但我需要复制一个文件,即使目的地存在。

But I need to copy a file even if the destination exists. Any workaround available in Qt for that?

推荐答案

if (QFile::exists("/home/user/dst.txt"))
{
    QFile::remove("/home/user/dst.txt");
}

QFile::copy("/home/user/src.txt", "/home/user/dst.txt");

这篇关于即使目标存在时也复制文件(在Qt中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆