// .txt
QFile txtFile(":/new/prefix1/saveddata.txt");
if (txtFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
// We're going to streaming text to the file
QTextStream stream(&txtFile);
stream << "testing\n";
stream << "testing\n";
txtFile.close();
}
I have a QFile
, which I am trying to open from the directory above. The file exists but does not open. Any idea why and how to fix it? Thanks.
The file path specified is a resource path, and resources probably cannot be modified, so the "open for writing" request fails. The Qt documentation for resources says nothing about writing data to resource files, only reading.
Resources are specifically designed for read-only data, so you need to use some other form of data storage if you want to modify the information.
See QSettings
for an alternative.