c++ - 我的程序无法写入 Windows 驱动器

标签 c++ qt

我有 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/

相关文章:

c++ - 堆栈溢出与我的析构函数

c++ - boost managed_mapped_file 使用我的物理内存吗?

qt - 如何在 Qt-Designer 中使用自定义小部件

android - 在 android 的 QTextEdit 中选择

c++ - 从 QGraphics GridLayout 中的 QTWidgets 中删除边框

c++ - 将以科学计数法表示的字符串转换为 float 和 double

c++ - 在编译器选项中定义字符串

c++ - 当一个类包含另一个类的实例时的类设计

c++ - 从 qrc 文件加载 .qss 主题

c++ - Qt QFile::size() 总是返回 0