Qt默認使用mingw編譯,不支持VS編譯器,因此,如果需要用VS開發,需要將Qt重新編譯。
前提:Qt已安裝(
http://qt.nokia.com/downloads-cn),VS已安裝。
1 下載Visual Studio Add-in
http://qt.nokia.com/downloads-cn2 安裝Visual Studio Add-in
3 重新編譯Qt
a) 用Visual Studio Command Prompt進行編譯。
開始菜單 --> Microsoft Visual Studio 2008 --> Visual Studio Tools --> Visual Studio Command Prompt。
注意:是使用Visual Studio Command Prompt,而不是直接的cmd Dos窗口。
b) 進入Qt的安裝目錄后,執行CD Qt,進入Qt的根目錄。
cd C:\Qt\2010.05\qt。
c) 運行命令 configure -platform win32-msvc2008。o(選擇opensource模式)回車,Y(同意license)回車
編譯時間我用了半個小時。
d) 運行命令nmake。
需要大概3個小時。
編譯期間會產生編譯錯誤,我編譯的是Windows 7下的VS2008版本。解決方法如下:
參考: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。
打開VS2008。Qt --> Options,增加Path:C:\Qt\2010.05\qt。
打開pro文件或者新建Qt項目即可。
如果之前是mingw版本,那么在增加path時可能出現:qt in the given path was built using mingw。
解決方法:刪除C:\Qt\2010.05\qt\lib下的libqtmain.a和libqtmaind.a,因為是通過找這2個文件判斷是否是mingw編譯版本。(可剪切到其他地方,以防再需要回到mingw版本)