• 6710阅读
  • 7回复

window下添加图标出错! [复制链接]

上一主题 下一主题
离线hczx2005906
 
只看楼主 倒序阅读 楼主  发表于: 2010-05-12
看了给window下添加图标的帖子
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, 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.


其实就是把你的图标转成 .ico 的文件,比如名为:myappico.ico。然后加个到 .rc文件中。

.rc文件使用记事本建立就行,其中添加一行

IDI_ICON1               ICON    DISCARDABLE     "myappico.ico"
保存

如果你使用 qmake 来生成你的makefile的话。就在.pro 文件中加入如下一行:

RC_FILE = myapp.rc

再在main函数的 Application  中添加
QApplication a(argc, argv);

   a.setWindowIcon(QIcon("win.ico"));
一切都是按照上面说的做的 怎么会出错?
怎么解决呢!

望高手指点下
离线hczx2005906
只看该作者 1楼 发表于: 2010-05-12
忘了说明一下 在window下的 QT 中编译的
离线yangfanxing
只看该作者 2楼 发表于: 2010-05-12
a.setWindowIcon(QIcon("win.ico"));
至少这个不对!qrc的话
":/dir/file"之类的才是正确的表达形式。搜搜老帖参考下~
PHPWind好恶心。。。不想看这种界面。。。
离线yangfanxing
只看该作者 3楼 发表于: 2010-05-12
PHPWind好恶心。。。不想看这种界面。。。
离线hczx2005906
只看该作者 4楼 发表于: 2010-05-12
看了 你说的帖子 也照做了  还是不行啊
qrc 的方法我以前也试过 是可以的 (在添加控件和菜单的图标的时候)
我现在想加的是应用程序的图标
ps:就像飞信、QQ 应用程序的图标一样的
离线yangfanxing
只看该作者 5楼 发表于: 2010-05-12
sorry,又看错了。
搜搜老帖吧!呵呵。。。
PHPWind好恶心。。。不想看这种界面。。。
离线dbzhang800

只看该作者 6楼 发表于: 2010-05-12
引用第4楼hczx2005906于2010-05-12 10:48发表的  :
看了 你说的帖子 也照做了  还是不行啊
qrc 的方法我以前也试过 是可以的 (在添加控件和菜单的图标的时候)
我现在想加的是应用程序的图标
ps:就像飞信、QQ 应用程序的图标一样的


1. 出错时应该是因为你没包含 QIcon 需要的头文件
2. 你不需要这条语句,直接删除
离线hczx2005906
只看该作者 7楼 发表于: 2010-05-13
回 5楼(yangfanxing) 的帖子
哈哈 问题解决 我用的图标不是标准的图标
快速回复
限100 字节
 
上一个 下一个