This article introducesQt resource fileUsed, like most GUI framework design tools,QtAlso introducedResource fileSystem. It is used to conveniently convert binary dataFile(Mainly ImagesFile) Compiled into the executable program, eliminating the trouble of additional files when releasing the application.
QtOfResource file
It is in XML text format with. qrc as the suffix. Use in the Qt ProjectResource fileAdd the following code to the. pro project file:
- RESOURCES = file.qrc
After such a statement is added to the project file, the qmake system automatically calls RCC (Resource fileCompiler) converts file. qrc to qrc_file.cpp, and finally uses gcc for normal compilation.
Basic Format of resource files
Let's 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 code between the main parts and the other parts can be copied. Here, "images/" is relative to youResource filePath, andResource file. You can use QFile in your source code to access them. In this example, because it is an image file, you can use QImage to access them directly. However, you must add the prefix ": /", in the form
- QImage(”:/images/copy.png”);
Resource file alias
If yourResource fileAnd put it in a relatively deep Directory, which can be simplified by alias
- images/cut.png
With the alias, you can use the alias to access the. cpp file.
- QImage(”:/cut-img.png”);
Internationalization of resource files
SomeResource fileYou may use differentResource file. You can also use the alias and language options. I didn't see the code.
- cut.jpg
- cut_fr.jpg
Before useResourcesIn the. cpp code, you can access differentResource file.
Summary:Qt resource fileAfter using the content, from the basic format of the resource file to the format of the resource file, the QT file is described in detail. I hope this content will be helpful to you. If possible, you can leave a message.