即时开发QT应用程序,我使用很少的图标
这是我的resource.qrc文件
<RCC>
<qresource prefix="/new/prefix1">
<file>army-officer-icon.png</file>
<file>uac.png</file>
</qresource>
</RCC>
Run Code Online (Sandbox Code Playgroud)
然后我将其包含在我的.pro文件中
RESOURCES += \
resource.qrc
Run Code Online (Sandbox Code Playgroud)
这是处理图标的代码:
//this code is part of the mainwindow.cpp
QSystemTrayIcon *trayIcon;
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/new/prefix1/army-officer-icon.png"));
trayIcon->show();
//this code is part of the ui_mainwindow.h (generated by QT)
QLabel *label_5;
label_5 = new QLabel(centralWidget);
label_5->setObjectName(QString::fromUtf8("label_5"));
label_5->setGeometry(QRect(40, 302, 46, 21));
label_5->setPixmap(QPixmap(QString::fromUtf8(":/new/prefix1/uac.png")));
label_5->show();
Run Code Online (Sandbox Code Playgroud)
所以,这看起来很合理吧?
=== windows 7,开发站,QT安装
结果效果也如我所料

我可以看到两个图标::托盘图标和uac shield =真棒
但当我搬到另一个工作站时,有些奇怪的事情发生了
=== windows XP,用户工作站,未安装QT

正如你所看到的,trayicon仍然有自己的图标,但是"uac shield icon"消失了...它非常令人不安,我真的不明白,因为这两个图标都是*.png格式,我浏览了很多,也许它与qt图像插件有联系(虽然我认为只有当我的图标是*.jpeg,*.gif格式时我才应该关心它),但是无法使这个解决方案有效...
所以欢迎任何想法.Thanx提前.
好吧,香港专业教育学院刚刚发布了这个(事实上,我很接近,但我复制了错误的路径:/)
找到C:\ QtSDK\Desktop\Qt\4.8.0\mingw\plugins
将插件/ imageformats复制到您的应用程序文件夹
打开main.cpp并添加这行代码
a.addLibraryPath(QCoreApplication::applicationDirPath ()+"/plugins");
Run Code Online (Sandbox Code Playgroud)编译,看看你漂亮的图标:)
| 归档时间: |
|
| 查看次数: |
1896 次 |
| 最近记录: |