[Qt-interest] How to edit a file present in a resource at run-time ?

Constantin Makshin cmakshin at gmail.com
Mon Nov 2 16:25:30 CET 2009


Don't worry about your antivirus, Windows itself doesn't allow a program  
to modify its executable. :)

On Mon, 02 Nov 2009 14:05:07 +0300, Andre Somers <andre at familiesomers.nl>  
wrote:
> 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é

-- 
Constantin Makshin



More information about the Qt-interest-old mailing list