[Qt-interest] How to edit a file present in a resource at run-time ?
Andre Somers
andre at familiesomers.nl
Mon Nov 2 12:05:07 CET 2009
Louis Du Verdier wrote:
> Hello,
>
> For a project, I have to edit a file present in a resource, but at
> run-time.
> I tried this code to test :
>
> QFile f(":/Test.txt");
> if(!f.open(QIODevice::ReadWrite | QIODevice::Text))
> {
> QMessageBox::critical(this, "Test", "Not working...");
> return;
> }
> f.write(QString("OK !").toAscii());
> QTextEdit *t = new QTextEdit(f.readAll());
> t->show();
>
> But the messageBox tell me that the file cannot be open in the
> ReadWrite mode.
> I took a look in QRessource but nothing speak about how to write into
> a file present in the ressource.
> So, how to write into a file present in the ressource when the
> application is running ?
>
The answer is simple: you don't.
The resource is compiled into the executable itself. You can not change
the executable you are running from that same executable. I hope my
anti-virus software would stop any program trying to do that...
I would work around your problem by storing the modified version of your
file on disk. You can then use the disk version if it exists, and the
embedded version if it doesn't.
André
More information about the Qt-interest-old
mailing list