Qt默認使用mingw編譯,不支持VS編譯器,因此,如果需要用VS開發,需要將Qt重新編譯。前提:Qt已安裝(http://qt.nokia.com/downloads-cn),VS已安裝。
1、下載Visual Studio Add-in
- http://qt.nokia.com/downloads-cn
2、安裝Visual Studio Add-in
3、重新編譯Qt
(1)用Visual Studio Command Prompt進行編譯。
開始菜單 --> Microsoft Visual Studio 2008 --> Visual Studio Tools --> Visual Studio Command Prompt。
注意:是使用Visual Studio Command Prompt,而不是直接的cmd Dos窗口。
(2)進入Qt的安裝目錄后,執行CD Qt,進入Qt的根目錄。
- cd C:\Qt\4.8.
(3)運行命令 configure -platform win32-msvc2008。o(選擇opensource模式)回車,Y(同意license)回車編譯時間我用了半個小時。
(4)運行命令nmake,需要大概3個小時。
C:\Qt\4.8.4>nmake
編譯期間會產生編譯錯誤,我編譯的是Windows 7下的VS2008版本。解決方法如下:
錯誤:
- api\qscriptextensionplugin.h(43): Error: Undefined
- interface
- NMAKE : fatal error U1077: 'C:\Qt\2010.05\qt\bin\moc.exe' : return
- code '0x1'
- Stop.
- NMAKE : fatal error U1077: '"c:\Program Files\Microsoft
- Visual Studio 9.0\VC\BIN
- \nmake.exe"' : return code '0x2'
- Stop.
- NMAKE :
- fatal error U1077: 'cd' : return code
- '0x2'
- Stop.
解決:
刪除
- C:/Qt/2010.05/qt/src/script/tmp/moc/debug_shared/mocinclude.tmp
- C:/Qt/2010.05/qt/src/script/tmp/moc/release_shared/mocinclude.tmp
其他錯誤解決:
刪除
- C:/Qt/2010.05/qt/src\3rdparty\webkit\WebCore\tmp\moc\debug_shared\mocinclude.tmp
- C:/Qt/2010.05/qt/src\3rdparty\webkit\WebCore\tmp\moc\release_shared\mocinclude.tmp
- 參考:http://tech.it168.com/a2010/1217/1139/000001139431_1.shtml
- http://developer.qt.nokia.com/wiki/QtVSAddin
- (通過源碼進行編譯配置)
- http://blog.csdn.net/hongqiang200/archive/2010/09/09/5873585.aspx
- (編譯錯誤解決)
4、配置VS。
配置VS
打開VS2008。Qt --> Options,增加Path:C:\Qt\2010.05\qt。
打開pro文件或者新建Qt項目即可。
如果之前是mingw版本,那么在增加path時可能出現:qt in the given path was built using mingw。
解決方法:刪除C:\Qt\4.8.4\lib下的libqtmain.a和libqtmaind.a,因為是通過找這2個文件判斷是否是mingw編譯版本。(可剪切到其他地方,以防再需要回到mingw版本)。