以下解决方案适用于Visual C++ 2013和MinGW,但这是Windows特有的。
将以下行添加到您的Qt项目文件中。
RC_FILE = WindowsResource.rc
现在创建在同一文件夹中的文本文件作为你的Qt项目文件并调用它WindowsResource.rc,你可以调用它,因为它是在Qt工程文件正确引用任何你想要的,只要。在记事本中打开它并插入以下行。
IDI_ICON1 ICON DISCARDABLE "MyIcon.ico"
现在把你在同一文件夹要作为Qt工程文件的图标,并调用它MyIcon.ico,你可以调用它,因为它是在Windows的资源文件中正确引用任何你想要的,只要你创建。
运行qmake并重建您的应用程序,该.exe文件现在应该显示在Windows资源管理器中,并带有新图标。
编辑: 我用Visual C++ 2013,它的工作。我引用的文章在http://support.microsoft.com/kb/2757355
Cause: This error can appear after installing Visual Studio 2012 side-by-side (SXS) with Visual Studio 2010 RTM or after installing .Net Framework 4.5 on a machine with Visual Studio 2010.
Resolution: To resolve this link error, upgrade Visual Studio 2010 RTM to VS 2010 SP1. Upgrading to VS 2010 SP1 resolves the dependency failure and the VC++ 2010 project builds with no LNK1123 error.
如果您正在使用Visual C++ 2010那么我建议你要确保你有安装Service Pack 1,我不知道在安装SP1将解决这一问题,但因为你是没有图标编译好。
不幸的是,这正是我正在做的,这导致链接错误。没有这个应用程序编译罚款。 – TheMPC 2014-09-20 23:09:06
感谢您的编辑,将在早上检查解决方案的第一件事。非常感激 :) – TheMPC 2014-09-21 00:14:33