PDA

View Full Version : how to update a local file at runtime



xyjian
4th March 2011, 04:08
In my project, there is a local data file to process. I used the resources to read it. But sometime this file will be updated online. I tried to write into the source file but failed.
Is there a way to solve this problem? thanks.

ChrisW67
4th March 2011, 04:40
If I understand you correctly, you want to modify a file that is embedded in the executable by way of Qt resources. You cannot do that.

The way to solve this problem is to have the file outside of the resource system and in a writeable location on the file system (i.e. NOT the C:\Program Files\MyProg folder).

xyjian
4th March 2011, 05:09
If I understand you correctly, you want to modify a file that is embedded in the executable by way of Qt resources. You cannot do that.

The way to solve this problem is to have the file outside of the resource system and in a writeable location on the file system (i.e. NOT the C:\Program Files\MyProg folder).

hi ChrisW67,
Thanks for your reply. I have a little puzzles still.
A Qt program have 2 folders: source folder and runtime folder. I created the data file in source folder and loaded the data file into resources. But If I used the outside path, I couldn't ensure where the data file is.
Could you please tell me how to set the file path. thank you

ChrisW67
4th March 2011, 05:55
The usual approach is to have your installer put the file in an allowable location for the target platform. Suitable locations can be identified using QDesktopServices::storageLocation().

During development (only!) you could use QCoreApplication::applicationDirPath() and put the file with the executable. DO NOT do this for a production system if you expect it to work.

xyjian
4th March 2011, 06:27
I see. thanks very much again!