注意,本教程的操作系统为 Win7 64位,VS2012 英文版。
由于机器是64位,编译Qt的过程中,有可能出现如下问题。
- fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
按照下面的教程,可以解决上面的编译错误。
1. 从 Qt 官网下载 qt-windows-opensource-5.1.0-msvc2012-x86_64-offline.exe,安装。
2. 下载 qt-vs-addin-1.2.2-opensource.exe,安装。
3. 添加环境变量 QTDIR,在我的机器上是下面的路径。
- D:QtQt5.1.05.1.0msvc2012_64
4. 添加Qt Version。
点击VS2012的菜单QT5 -> Qt Options,在弹出的窗口中,点击Add,在Path的输入框中,输入下面的路径,注意对应修改为你机器上的路径。
- D:QtQt5.1.05.1.0msvc2012_64
5. 在VS2012中新建一个Qt Project,HelloQt
6. 在Solution Explorer右键点击项目HelloQt -> Properties,点击弹出窗口右上角的Configuration Manager,修改Platform为x64。
6. 在Solution Explorer右键点击项目HelloQt -> Properties -> Configuration Properties -> Linker -> Advanced,点击 Target Machine 修改为X64。
7. 在Solution Explorer右键点击项目HelloQt -> Qt Project Settings,在弹出的窗口中,点击Version的下拉框,选择msvc2012_64。
现在,Ctrl + F5 应该可以正常运行啦。如果还不行,在Solution Explorer右键点击项目HelloQt -> Rebuild。