我有以下问题,我有一个名为 data.txt 的资源文件,我想用写权限打开它。我使用 QFile 和 QTextStream 来处理它。我只能使用 ReadOnly Acces 打开文件,但不能使用 ReadWrite 或 WriteOnly 访问。具有类似代码的导出函数可以正常工作,只是不能在资源文件上工作。
我已经尝试将前斜杠更改为双反斜杠,我运行了一百次 qmake 并重新构建,我重新启动计算机并重新启动资源文件。我已经检查了 Stack 上的很多条目,但无法找到解决我的问题的条目。(大多数问题都是拼写问题,比如只有一个反斜杠)。
QFile file(":/savelocation/data.txt");
if (!file.exists())
{
qDebug()<<"File not exist";
}
file.open(QIODevice::ReadWrite | QIODevice::Text);
if (file.isOpen())
{
qDebug()<<"File is open";
QTextStream out(&file);
out<< "something" << endl;
}
else
{
qDebug()<<"File is not open";
}
file.close();
file.open(QIODevice::ReadOnly);
if (file.isOpen())
{
qDebug()<<"File is open as read only";
}
else
{
qDebug()<<"File is not open as read only";
}
file.close();
实际结果:
代码的我的应用程序输出:文件未打开文件以只读方式打开它只能以只读方式打开它。
在我实施之前,如果我得到以下输出:
QIODevice::write (QFile,":/savelocation/data.txt"): device not open
预期结果:
该文件将以写访问权限打开。
提前致谢。