Use to parse Qt resource files

Source: Internet
Author: User

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:

 
 
  1. 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.

 
 
  1. images/copy.png  
  2. images/cut.png  
  3. images/new.png  
  4. images/open.png  
  5. images/paste.png  
  6. 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

 
 
  1. QImage(”:/images/copy.png”); 

Resource file alias

If yourResource fileAnd put it in a relatively deep Directory, which can be simplified by alias

 
 
  1. images/cut.png 

With the alias, you can use the alias to access the. cpp file.

 
 
  1. 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.

 
 
  1. cut.jpg  
  2. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.