一直以来很纠结给qt应用程序添加图标问题,在网上收过一次,但是感觉不够完整,现将自己的实现过程记录下,以便以后查看:

通过网上的例子知道qt助手中有相关说明:

Setting the Application Icon

The application icon, typically displayed in the top-left corner of an application's top-level windows, is set by calling theQWidget::setWindowIcon() method on top-level widgets.

In order to change the icon of the executable application file itself, as it is presented on the desktop (i.e., prior to application execution), it is necessary to employ another, platform-dependent technique.

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++: SelectFile|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, create a text file called, say, myapp.rc in which you put a single line of text:

 IDI_ICON1               ICON    DISCARDABLE     "myappico.ico"

Finally, assuming you are using qmake to generate your makefiles, add this line to your myapp.pro file:

 RC_FILE = myapp.rc

Regenerate your makefile and your application. The .exe file will now be represented with your icon in Explorer.

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

从上面可将方法分为两种:

1.使用软件的方法可设置程序窗口的默认图标,但是它无法改变应用程序文件.exe的图标。

2.使用qmake生成makefile的,如qt+eclipse,qt creator通过”If you do not use qmake"之前的方法就可以解决

3.使用qt+vs2010不是用qmake的情况,需要执行"If you do not use qmake..."方法,先将.rc文件添加到工程中,再编译.rc文件,最后重新连接下即可改变图标。

实现过程:

1.设置应用程序运行时所有窗口默认图标,

  1. QApplication a(argc, argv);
  2. //获得可执行程序路径
  1. QString dir = QApplication::applicationDirPath();
  2. //设置可执行程序路径为当前工作路径
  3. QDir::setCurrent(dir);
  4. QApplication::addLibraryPath("./plugins");
  1. QApplication::addLibraryPath("./images");
  2. a.setWindowIcon(QIcon("./images/myappico.ico"));

2.通过qmake生成makefile实现过程:

a.找到一张图片.ico,名字改为myappico.ico;

b.创建一个新的文本文档,内部添加  IDI_ICON1           ICON   DISCARDABLE   "myappico.ico",并将文件重命名为myapp.rc;

c.在myapp.pro文件最后加上RC_FILE = myapp.rc,重新生成之后,就修改成功了
3.不用qmake生成makefile实现过程:

前面两步骤一样,最后一步改为,将.rc文件加载至工程中,通过右键工程——添加——已存在文件,添加后右键.rc文件编译,重新生成可执行文件后就修改成功了

设置Qt应用程序图标及应用程序名 【转载】的更多相关文章

  1. 【转】设置Qt应用程序图标及应用程序名

    一直以来很纠结给qt应用程序添加图标问题,在网上收过一次,但是感觉不够完整,现将自己的实现过程记录下,以便以后查看: 通过网上的例子知道qt助手中有相关说明: Setting the Applicat ...

  2. 【Qt开发】设置Qt应用程序图标

    [Qt开发]设置Qt应用程序图标 标签:[Qt开发] 首先,准备一个图标,例如:zx.ico,并新建一个文本文档,在里面添加一行: IDI_ICON1 ICON DISCARDABLE"zx ...

  3. 设置QT应用程序图标方法(Windows下)

    学习笔记,言简意赅. 1- 新建文本文件,编辑输入  IDI_ICON1   ICON    DISCARDABLE     "./image/WindowIco.ico" 注意: ...

  4. QT添加程序图标及窗口图标

    程序图标 材料准备 图标文件:*.ico文件,存放在源文件同一目录下,如"myapp.ico" 写入图标 向*.pro文件中,独立一行写入"RC_ICONS = *.ic ...

  5. Qt应用程序图标设置

    Qt应用程序图标设置 本文仅仅适用于windows下,linux等不适用. 下面说的图标,指的是程序文件的图标,而不是托盘图标或者说运行时任务栏的图标(任务栏和程序窗口的图标在windows/linu ...

  6. Qt应用程序图标

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt应用程序图标     本文地址:http://techieliang.com/2017/1 ...

  7. Qt 添加程序图标和系统托盘图标

    添加程序图标 第一种方法: 1.创建程序的时候,选择添加默认图标 2.替换程序目录下的ico文件,编译生成即可. 第二种方法: 比较适合一开始没有添加程序图标的情况 1.项目右键-->添加--& ...

  8. QT更改程序图标

    方法只要几个步骤就好了,如下: 1.准备好一个ico格式的图标文件,例如demo.ico 2.创建一个rc文件, 例如demo.rc. 并copy下面代码: // Generated by ResEd ...

  9. 设置 Qt GUI程序 printf输出到独立控制台

随机推荐

  1. PHPExcel读写封装

    <? require_once ('inc/PHPExcel/PHPExcel/IOFactory.php'); /** * @author lgl * 使用实例 * $fieldMap=['昵 ...

  2. css transform常用变化解析

    本文旨在对常用变化做最直观的简析 translate 移动 translateX() X轴正方向移动(单位可为px,也可为%,为%时以自身为参照物) translateY() Y轴反方向移动 tran ...

  3. Android LCD(一):LCD基本原理【转】

    本文转载自:http://blog.csdn.net/longxiaowu/article/details/24787597 关键词:Android LCD TFT 液晶 偏光片 彩色滤光片  背光 ...

  4. 4950: [Wf2017]Mission Improbable

    4950: [Wf2017]Mission Improbable Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 608  Solved: 222[Sub ...

  5. 【arc101】比赛记录

    这场还好切出了D,rt应该能涨,然而这场的题有点毒瘤,700分的D没多少人切,更别说EF了.(暴打出题人)既然这样,干脆就水一篇博客,做个简单的比赛记录. C - Candles 这题是一道一眼题,花 ...

  6. nginxif多条件结合判断(实现限速)

    参考文章: https://yq.aliyun.com/articles/44957 需求: 要对某一ip下,使用android客户端的用户进行限速 原理 就是用SET变量进行. AND 就用变量叠加 ...

  7. JavaScript -- 练习 window 流氓广告

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. JNI_C#

    1. 基本就是 通过 JAVA --> C/C++ --> C#的DLL 2. (1).自己写 JNI与 C#的DLL 通信 http://www.cnblogs.com/yinhaimi ...

  9. java.lang.Exception: No runnable methods at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)

    使用方法测试时出现以下错误 java.lang.Exception: No runnable methods at org.junit.runners.BlockJUnit4ClassRunner.v ...

  10. numpy函数:[6]arange()详解

    arange函数用于创建等差数组,使用频率非常高,arange非常类似range函数,会python的人肯定经常用range函数,比如在for循环中,几乎都用到了range,下面我们通过range来学 ...