Add images to resource files in QT

Source: Internet
Author: User

Image is needed for a recent task. So I certainly put a bunch of images to the currentProgramThe result image cannot be displayed. After a day or two, consider whether the image size or resolution is a problem. I asked someone in the Forum and found the reason. Path reason. You only need to put the image under the debug file to display it. Read from othersArticle:

 
Qdir Dir;
 
Qstring Pathname;
 
Pathname = Dir. currentpath ();
 
Qdebug () <pathname;

The aboveCodeThe current working directory is displayed:"C:/users/admin/build-yinspect-SS-Debug"

I put the image in"C:/users/admin/build-yinspect-SS-Debug"
The image is displayed normally.


Later, I used a resource file to display images, so I added a resource file. But it is not shown. I will try again to get the resource file in a few days. Finally, we got it right.

1. Add a resource file, such as IMG. qrc.

2. Add a prefix, such as button

3. Add images. It is best to put your images in the program directory to facilitate the transfer process.

4. When using images, for example:Qicon(":/Button/Image/1.png")

I think there is an imagefile in the program directory and there is a 1.png image in it. Don't forget to add it.


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.