我有 windows 8.1 x64,但我无法在我的 windows 驱动器上写入文件。当我运行以下代码时没有任何反应:
void MainWindow::on_actionBackup_Database_triggered()
{
QFile en1;
en1.copy("En1.txt","C:\\En1.txt");
}
现在,如果我将此代码更改为:
void MainWindow::on_actionBackup_Database_triggered()
{
QFile en1;
en1.copy("En1.txt","E:\\En1.txt"); // change C to E
}
代码将正常工作。为什么是这样?请注意,我的 C 盘是我的操作系统盘。
最佳答案
复制函数返回一个 boolean
值,指示复制是否成功。
您应该使用它来查看它是否复制成功并处理它没有复制的情况。
它不复制的原因可能是您的 c:\驱动器上的文件权限。您可以更改此设置,但如果可能,您最好选择另一个目录。
http://doc.qt.io/qt-4.8/qfile.html#copy
bool QFile::copy(const QString & newName)
Copies the file currently specified by fileName() to a file called newName. Returns true if successful; otherwise returns false.
Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it).
The source file is closed before it is copied.
关于c++ - 我的程序无法写入 Windows 驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318043/