Qt/C++:在 Windows 操作系统下运行程序时不显示图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6516299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt/C++: Icons not showing up when program is run under windows O.S
提问by Jens
I am using QT 4.7.0. I have created a project in Windows. I am using some icons on buttons, but when I move the .exe file to another Windows machine the icons don't show. If I run the program in the on the development machine, the icons appear.
我正在使用 QT 4.7.0。我在 Windows 中创建了一个项目。我在按钮上使用了一些图标,但是当我将 .exe 文件移动到另一台 Windows 机器时,图标不显示。如果我在开发机器上运行程序,图标就会出现。
I created a qrc file and added the icons to it.
我创建了一个 qrc 文件并将图标添加到其中。
回答by O.C.
回答by Jens
Your code needs to reference the icons in the resource bundle and not the icons with harddisk paths, e.g.
您的代码需要引用资源包中的图标,而不是带有硬盘路径的图标,例如
QIcon icon(":/resources/icon.ico");
and not
并不是
QIcon icon("resources/icon.ico");
Profiling a debug version on the target machine with depends.exe will help you show, whether OrcunC or my guess is correct.
使用depends.exe 在目标机器上分析调试版本将帮助您显示OrcunC 或我的猜测是否正确。
回答by Lwin Htoo Ko
I think you need to link the image plugin dlls at run time.
我认为您需要在运行时链接图像插件 dll。
copy necessary dlls in the plugins folder from your Qt directory into your deployment directory and load it.
将 plugins 文件夹中的必要 dll 从 Qt 目录复制到部署目录并加载它。
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString sDir = QCoreApplication::applicationDirPath();
a.addLibraryPath(sDir+"/plugins");
//*********** do your things
return a.exec();
}
回答by PeanutStars
Please see this page if you can not solve it currently.
如果您目前无法解决,请查看此页面。