How does Qt add ico pictures to exe

1. Create a folder and prepare files

Create an images folder in the top-level directory of the project, then download the ico icon you think is ok or the UI design, and then create an rc file, such as the logo.ico and logo.rc I put here:

 

Then the content of logo.rc is as follows (you can open it with a text editor, such as notepad++):

IDI_ICON1 ICON DISCARDABLE "logo.ico"

Because Qt creator cannot directly create folders, we need to create them here first.

2. Add files

Right-click the project to add:

 

Here I feel that there is a bug in Qt creator, which is the problem of file case display. After I change the uppercase of the file to lowercase, when I add a folder here, it will display the existing files that I have capitalized before by default, and it will be displayed by default. Check it, if you don’t pay attention, you will be sure to add a lot of files to the .pro file. At this time, an error will be reported when compiling, showing that many functions are repeatedly defined:

 

3. Modify project files

Then add the following information at the end of the .pro project file (note the path):

RC_FILE += images/logo.rc

 

4. Recompile

After recompiling, you will find that the exe has an icon. After packaging it into an exe and installing it on other computers, it will also have a corresponding icon:

The benefits of this article, free to receive Qt development learning materials package, technical video, including (C++ language foundation, C++ design pattern, introduction to Qt programming, QT signal and slot mechanism, QT interface development-image drawing, QT network, QT database programming, QT project actual combat, QSS, OpenCV, Quick module, interview questions, etc.) ↓↓↓↓↓↓See below↓↓Click on the bottom of the article to receive the fee↓↓

Guess you like

Origin blog.csdn.net/m0_60259116/article/details/130411733