PDA

View Full Version : Edit resource file of compiled executable



jwz104
10th August 2016, 13:45
I want to change the resource file(It contains an textfile with some settings) of an qt linux c++ application with another application.
I know this is possible in c# and delphi because I did it there before. But is this possible in qt c++? And does someone has an example for me?

This is what the resource file contains:


<RCC>
<qresource prefix="/">
<file>settings.txt</file>
</qresource>
</RCC>

ChrisW67
10th August 2016, 14:30
Qt resources, referenced by the qrc file, are compressed, converted to C++ code, and compiled into the Qt C++ program. This is distinctly different from the Windows Resources that you were likely editing in your Delphi/.Net programs: these are stored as blobs embeded in the same files as the compiled executable, but logically separate from it and addressable through an API. Windows resources can be edited, added and removed by third party products with no knowledge of the executable.

You can use the Qt Resource Compiler to produce standalone binary files that can be loaded dynamically, and selected at run time.
http://doc.qt.io/qt-4.8/resources.html

You are free to use Windows resources in your Qt C++ program and the Windows API to access them. See the RC_FILE variable in qmake. This is not as convenient as the qt resource system for some applications.

jwz104
10th August 2016, 15:25
I forgot to say that it is a linux application?
Is it now impossible?

anda_skoa
10th August 2016, 17:48
The platform doesn't change anything on how Qt's resources work.

As ChrisW67 explained, the technique used here is to take the data, compress it and then generate C++ code (char arrays) and compile them like any manually written C++ code.

QFile and QDir know about these "files" and map them into a kind of virtual filesystem, so Qt classes that expect a file name or URL can still access the data.
The data is not a real file anymore though.

Just like any normal char array constant that data is now part of the executables read-only section, which makes it shared between multiple instances of the same program.

Cheers,
_