QT Resource Usage and resource occupancy ... (You can load resource files dynamically, which does not account for memory)

Source: Internet
Author: User

Original Address:About the use of resources under QT and the excessive memory consumption of resources Technical Achievement Dream Recently, we study how to invoke the image from the outside, and then study how to use the image resource. The most common online post is this, the feeling summed up is also good.    Http://www.cnblogs.com/lzjsky/archive/2012/08/20/2647471.html in general, there are two ways of doing it. One is the use of QRC resource files, that is, in the QT project to add resource files, this method is relatively simple and easy to operate, for beginners more easy to use, when the resources are relatively small can be used. However, it is also a disadvantage, that is, the added resource files (such as qrc.cpp) will be stored directly into the static array, thus occupying memory, so that memory utilization is not high.    Sometimes, if the resources are too large, the compilation may fail, resulting in an out of memory error. At this point, a second approach is required by referencing the resource binaries externally (typically RCC files).    Specific use method see above the post, write very detailed.    Here is the main point of feeling written in the details of the place.    This post is mainly for the QT platform under Windows. The first thing to do is to generate a binary file of resources, In the QT project first to add resource files (. qrc format, will not add the first to learn how to use QRC bar), all the picture resources to add success, save the project, in the. qrc format of the file right-click, choose here to open the command desk (that is, the usual DOS format), open and then enter the command rcc-binary name.qrc-o NAME.RCCTo turn the QRC resource file into an RCC binary resource file. The resulting RCC binaries are located in the project directory. Then, the next step is to register.       About QT Registration Management mechanism, the above post is introduced.       How do I register??       Before registering, please delete the QRC file you created in the project, otherwise it doesn't make any sense, QRC is used to generate RCC files. First, copy the generated RCC file to the directory of your executable file, either Debug or release. Then call the function Qresource::registerresource ("DEBUG/ABC.RCC"); Note that if you do not have debug, the registration will not succeed. Why do I need a debug before? This involves a relative path to the problem, I did not do more research. In simple terms, relative paths are relative to Current Working Directory , So if you think you don't know the current working directory, then you canQdebug () << qdir::currentpath (); So you can know your current working directory, know the current working directory, you can easily choose the relative directory.     After registering successfully, you can see the corresponding memory consumption through the Task Manager, and you will find that the memory is increased, which is the size of the resource file you added. Once the registration is complete, it can be used in a way that uses QRC resources.     The original how to operate, now also how to operate.     If you do not want to use this part of the resource, you can use the anti-registration to remove this part of the resource from memory.          Call Qresource::unregisterresource ("DEBUG/ABC.RCC");//This allows the resource to be removed from memory, saving memory. In this process, a problem was found. is about the setstylesheet problem. UI, Label, Setstylesheet ("Qlabel{border-image:url (:/home/image/dsc05363.jpg);}");Here, it is also a question to illustrate. Why is there a colon in front of the path.       This path is also a relative path, with a colon indicating the relative path to the QRC resource file. As shown above, after registering the resource, according to the method of using QRC resources can call the picture, but once the image is called into the label, the memory will increase sharply, the original picture (in the format of JPG format) is 4M, the call into the label, the increase of about 93M of memory,     The memory will revert to its original size (under Windows QT) only after the label label has been emptied. Originally, Qt in the operation of the picture, is the external picture by the pixel write, after the experiment found, regardless of the format of the picture, regardless of size, as long as the pixel is the same, then Qt will write the picture in the control after the memory is the same, the increase in memory is not the size of the picture itself, but increased several times,    and is related to the size of the control being used, which inevitably leads to an increase in memory usage. When you use a lot of tags and other controls in your project, and you need a large number of external images to cover these controls, when you frequently use these controls, there is a lot of memory, and it is a cumulative trend, resulting in a memory overflow error. This time can use a multi-process approach, you can make different interfaces into different processes, when the interface operation is completed, the process of shutting down, the process consumes the memory is emptied, only when the process switch may be slower speed, but can be guaranteed to consume less memory resources.

Http://www.cnblogs.com/swarmbees/p/5621403.html

QT Resource Usage and resource occupancy ... (You can load resource files dynamically, which does not account for memory)

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.