【问题标题】:QFile open file for writing failsQFile 打开文件写入失败
【发布时间】:2011-03-29 19:17:50
【问题描述】:

我正在尝试打开文件并将一些文本数据写入其中。

QFile out(":/test.txt");
if (!out.open(QIODevice::ReadWrite)) {
    QMessageBox msgBox;
    msgBox.setText(out.errorString());
    msgBox.exec();
    return;
}

但它因“未知错误”而失败。 (Qt 4.6,Wnidows XP SP3)

【问题讨论】:

  • 如果你只是想写,使用WriteOnly。 (但这无论如何都不适用于资源文件,正如 Roku 解释的那样)。

标签: c++ qt qfile


【解决方案1】:

":/test.txt" 是嵌入到可执行文件中的resource file 的名称,您无法对其进行写入。例如将文件名更改为“C:/test.txt”。

【解决方案2】:

你需要改变你的 QFile 构造函数参数

QFile out(":/test.txt");

可能是正确的路径

QFile out("./test.txt");

QFile out("C:/test.txt");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    相关资源
    最近更新 更多