Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt QFile myFile.copy(newFile)失败,但myFile.error返回0(这意味着无错误)_Qt_Copy_Qfile - Fatal编程技术网

Qt QFile myFile.copy(newFile)失败,但myFile.error返回0(这意味着无错误)

Qt QFile myFile.copy(newFile)失败,但myFile.error返回0(这意味着无错误),qt,copy,qfile,Qt,Copy,Qfile,我将Qt 4.6.3与SUSE 11 Linux一起使用,并尝试使用QFile复制一个文件: QFile myFile ("/my/path/myFile.txt"); if (!myFile.copy("/my/otherpath/myNewFile.txt")){ cout << "Qt error: " << myFile.error() << endl; } 在我的C++程序中,MyField.Copy.()返回“false”,但是MyFi

我将Qt 4.6.3与SUSE 11 Linux一起使用,并尝试使用QFile复制一个文件:

QFile myFile ("/my/path/myFile.txt");

if (!myFile.copy("/my/otherpath/myNewFile.txt")){
    cout << "Qt error: " << myFile.error() << endl;
}
<>在我的C++程序中,MyField.Copy.()返回“false”,但是MyField.Error()返回“0”。 我希望myFile.error()返回的值不是“0”

此外,我尝试了myFile.errorString(),结果是“未知错误”


是否可能获得错误代码或消息,如“设备上没有剩余空间”?

很可能目标文件已经存在。文件说:

如果名为
newName
的文件已存在,
copy()
返回false

这不是实际的错误情况,因为
copy()
不覆盖是正常的。检查它的存在。检查文件错误时,请使用错误枚举进行检查,例如:

QFile from("fromFile");
QFile target("targetFile");
if (target.exists())
    target.remove();
if (target.error() != QFile::NoError)
    // remove error
from.copy(target.fileName());
if (from.error() != QFile::NoError)
    // copy error

很可能目标文件已经存在。文件说:

如果名为
newName
的文件已存在,
copy()
返回false

这不是实际的错误情况,因为
copy()
不覆盖是正常的。检查它的存在。检查文件错误时,请使用错误枚举进行检查,例如:

QFile from("fromFile");
QFile target("targetFile");
if (target.exists())
    target.remove();
if (target.error() != QFile::NoError)
    // remove error
from.copy(target.fileName());
if (from.error() != QFile::NoError)
    // copy error

谢谢!是,目标文件已退出。那是我的错。谢谢!是,目标文件已退出。那是我的错。