【第八篇】Qt学习与使用---设置应用程序的ICON图标

一、问题背景

整个程序编完之后,想要设置一下程序图标,结果遇到了困难。

仿照网上的说的方法:

win32:RC_FILE += ico.rc
或者
RC_ICONS = ico.ico

发现自己始终报错误:

:-1: error: [release/DrawTable_res.o] Error 1

二、请教官方帮助手册

在QT的“帮助”中,搜索 application icon,即可得到帮助文件。在windows中的操作帮助如下:

Setting the Application Icon on Windows

First, create an ICO format bitmap file that contains the icon image. 
This can be done with e.g. Microsoft Visual C++: 
Select File|New, then select the File tab in the dialog that appears, and choose Icon. 
(Note that you do not need to load your application into Visual C++; 
here we are only using the icon editor.)
Store the ICO file in your application's source code directory, 
for example, with the name myappico.ico.

Then, assuming you are using qmake to generate your makefiles, 
you only need to add a single line to your .pro project file:

  RC_ICONS = myappico.ico

Finally, regenerate your makefile and your application. 
The .exe file will now be represented by your icon in Explorer.

However, if you already have an .rc file, for example, with the name myapp.rc, 
which you want to reuse, the following two steps will be required. 

First, put a single line of text to the myapp.rc file:

  IDI_ICON1               ICON    DISCARDABLE     "myappico.ico"

Then, add this line to your myapp.pro file:

  RC_FILE = myapp.rc

If you do not use qmake, the necessary steps are: 
first, create an .rc file and run the rc or windres program on the .rc file, 
then link your application with the resulting .res file. 



google翻译如下:

在Windows上设置应用程序图标

首先,创建一个包含图标图像的ICO格式位图文件。
这可以通过例如Microsoft Visual C ++:
选择File | New,然后在出现的对话框中选择File选项卡,然后选择Icon。
(请注意,您无需将应用程序加载到Visual C ++中;
在这里,我们仅使用图标编辑器。)
将ICO文件存储在应用程序的源代码目录中,
例如,名称为myappico.ico。

然后,假设您正在使用qmake生成makefile,
您只需要在.pro项目文件中添加一行:

  RC_ICONS = myappico.ico

最后,重新生成您的makefile和您的应用程序。
现在,.exe文件将由资源管理器中的图标表示。

但是,如果您已经有一个.rc文件(例如,名称为myapp.rc),
要重复使用,则需要执行以下两个步骤。

首先,将一行文本放入myapp.rc文件中:

  IDI_ICON1不可显示的图标“ myappico.ico”

然后,将此行添加到您的myapp.pro文件中:

  RC_FILE = myapp.rc

如果不使用qmake,则必需的步骤是:
首先,创建一个.rc文件,并对该.rc文件运行rc或windres程序,
然后将您的应用程序与生成的.res文件链接。

三、问题分析

http://www.voidcn.com/article/p-ufugumjf-bmd.html

https://blog.csdn.net/liang19890820/article/details/52702523

猜你喜欢

转载自blog.csdn.net/Kshine2017/article/details/102514086