Parsing qt Resource File usage
Transferred from: http://mobile.51cto.com/symbian-270121.htm
This article introduces the use of QT files in detail, and, like most GUI framework design tools, QT introduces a resource file system. It is used to easily compile some binaries (mostly picture files) into an executable program, eliminating the hassle of attaching other files when the application is republished.
This article describes the use of qt resource Files , and, like most GUI framework design tools,qt introduces a resource file system. It is used to easily compile some binaries (mostly picture files ) into an executable program, eliminating the hassle of attaching other files when the application is republished.
resource Files for Qt
is an XML text format with a suffix of. Qrc. To use resource files in a QT project, you need to add the following code to the. Pro Project file
- RESOURCES = FILE.QRC
When such a statement is added to the project file, the Qmake system automatically calls the RCC ( resource file compiler) to convert the FILE.QRC to Qrc_file.cpp and finally uses GCC for normal compilation.
Basic format for resource files
Take a look at a simple. QRC example
- Images/copy.png
- Images/cut.png
- Images/new.png
- Images/open.png
- Images/paste.png
- Images/save.png
The main part and the code between the other parts copied over it, here the "images/" is relative to the path of your resource file , and the format of the resource file is not related. Then you can use Qfile in your source code to access them, in this case, because it is a picture file, then you can also access them directly with Qimage, but preceded by the prefix ":/", in the form of
- Qimage (":/images/copy.png");
Alias for resource file
If you have more resource files and are placed in a deeper directory, you can simplify them by using aliases.
- Images/cut.png
When you have an alias, you can access it in the. cpp file by using an alias
- Qimage (":/cut-img.png");
Internationalization of resource files
Some resource files may use different resource files depending on the language in which they are used. can also be implemented by aliases and language options, I did not look at the code
- Cut.jpg
- Cut_fr.jpg
In the. CPP code that uses the above resources , different resource files can be accessed through the same statement qimage (":/cut.jpg"), depending on the system lang.
Summary:qt resource File usage content is finished, from the basic format of the resource file to the format of the resource file, a detailed introduction of the QT file. I hope this content is helpful to you, if you have a situation, you can leave a message.
[Go] parsing qt resource file usage