本文將使用簡單的幾個步驟說明在VC 2005下如何編譯安裝並開發Qt4.6應用程序,其實大部分方法和Qt4.6.0是同樣的,不過Qt4.6.0集成了Qt Creater,目錄的形式有點改變了,如今我就把個人安裝方法分享給你們(首先保證你的Qt安裝目錄所在的磁盤有5G空間,由於個人是徹底編譯,除了例子,加上例子應該是10G多):css
1、下載及安裝mysql
1. 下載,直接找官網下載就能夠了,個人是qt-win-opensource-4.6.0-beta1-mingw.exec++
2. 設置環境變量:web
個人電腦>屬性>高級>環境變量>用戶變量裏面設置幾個變量(我把QT裝在了D盤中,且使用了它默認的目錄):sql
PATH中增長C:/Qt/4.6.0-beta1/bin(注意:這個與Qt4.4.3就不同了,多了一級目錄);windows
建立QMAKESPEC值爲 win32-msvc2005,這個值仍是根據你要生成的Vs版本,6.0 使用win32-msvc, 2003 使用win32-msvc.net, 2005就是 win32-msvc2005 ;函數
建立QTDIR值爲 C:/Qt/4.6.0-beta1工具
最後爲了使的你剛纔修改的環境變量生效,重啓cmd,能夠經過C:/>qmake -v來看你使用的QT版本,應該顯示的是Qt4.6.0.ui
3. 從VC 2005的安裝路徑找到vsvars32.bat(以你本身的安裝目錄爲準,個人是D:/Program Files/Microsoft Visual Studio 8/Common7/Tools):this
運行cmd
C:/> D:
C:/>cd D:/Program Files/Microsoft Visual Studio 8/Common7/Tools
D:/>Program Files/Microsoft Visual Studio 8/Common7/Tools> vsvars32.bat
D:/> cd D:/Qt/2009.03/qt
D:/Qt/2009.03/qt> configure -debug-and-release -platform win32-msvc2005 -opensource -stl -fast -vcproj
configure -debug-and-release 參數的意義是告訴QT同時編譯爲Debug和Release兩個版本的庫,不指定參數則編譯爲Debug版本的動態連接庫若是安裝了多個版本的VS能夠加上-platform win32-msvc2005(表示VS2005的),6.0 使用win32-msvc, 2003 使用win32-msvc.net, 2008就是win32-msvc2008。configure大約須要幾分鐘,-nomake examples -nomake demos就是不編譯例子,值錢我介紹的把這兩個目錄移走的方法不太好。可是按個人這個configure變異的話,會有問題的,編譯不經過,由於個人這是徹底編譯,我編譯了3次才過的,每次到編譯webkit的時候就出錯,聽說這是Qt4.5的bug,可是我從網上找到了解決辦法,就是在configure以後先不要nmake,刪除D:/Qt/2009.03/qt/src/3rdparty/webkit/WebCore/tmp/moc/debug_shared/mocinclude.tmp文件和D:/Qt/2009.03/qt/src/3rdparty/webkit/WebCore/tmp/moc/release_shared/mocinclude.tmp文件,而後再namke吧,必定成功得,呵呵~
下面是我從網上搜索到的configure的具體參數,供你們編譯參考:
我的認爲只須要加個 -fast參數就ok了。其餘參數視本身狀況而定,好比你不須要qt3支持能夠添加-no-qt3support,或者不須要webkit插件 -no-webkit
配置參數選項:
前面是*號的表示默認參數. +號表示該功能要求被評估,評估成功後才能被接受.
-release ........... 調試關閉.沒有調試庫,本身的項目只能發佈,不能調試(沒有調試庫的緣故),若是你硬要編譯debug版本的話,會提示找不到xxxxxd.dll
* -debug ............. 只有調試庫,沒有釋放庫,也就是說之後本身的項目只能調試,若是你硬要編譯debug版本的話,會提示找不到xxxxx.dll
+ -debug-and-release . 編譯後包含兩種庫。最好編譯兩種庫
-opensource ........ 編譯開源版.
-commercial ........ 編譯商業版. 這兩個參數通常不需指定,configure開始須要你選擇版本。
-developer-build ... 編譯開發者選項。
* -shared ............動態編譯.
-static ............ 靜態連接庫.貌似有插件不能用靜態編譯。
* -no-fast ........... configure生成全部項目makefiles文件,並編譯
-fast .............. 只生成庫目錄及子目錄下的項目的makefiles文件.
-no-exceptions ..... 關閉異常支持
* -exceptions ........ 開啓異常支持.
-no-accessibility .. 關閉對windows active控件支持.
* -accessibility .....對windows active控件支持.
-no-stl ............ 無c++標準庫支持
* -stl ............... 有標準庫支持
尖括號在blogger出問題了。。。。。
-no-sql- ... Disable SQL entirely, by default none are turned on.
-qt-sql- ... Enable a SQL in the Qt Library.
-plugin-sql- Enable SQL as a plugin to be linked to at runtime.
Available values for :
mysql
psql
oci
odbc
tds
db2
+ sqlite
sqlite2
ibase
(drivers marked with a '+' have been detected as available on this system)
-system-sqlite ..... Use sqlite from the operating system.
-no-qt3support ..... 不提供對qt3函數支持
-no-opengl ......... 不提供OpenGL函數支持
-platform ... The operating system and compiler you are building on.
(default %QMAKESPEC%)
-xplatform .. The operating system and compiler you are cross compiling to.
See the README file for a list of supported operating systems and compilers.
-qtnamespace Wraps all Qt library code in 'namespace name {...}
-D ........ Add an explicit define to the preprocessor.
-I ... Add an explicit include path.
-L ... Add an explicit library path.
-l ... Add an explicit library name, residing in a librarypath.
-graphicssystem Specify which graphicssystem should be used.
Available values for :
* raster - Software rasterizer
opengl - Using OpenGL accelleration, experimental!
-help, -h, -? ...... Display this information.
第三方庫
-qt-zlib ........... 使用zlib綁定到qt.
+ -system-zlib ....... 使用操做系統的zlib
見 http://www.gzip.org/zlib
-no-gif ............ 不編譯gif文件讀取支持插件
+ -qt-gif ............ 編譯gif文件讀取支持插件
參見 src/plugins/imageformats/gif/qgifhandler.h
-no-libpng ......... 不編譯PNG支持插件.
-qt-libpng ......... 編譯PNG支持插件.
+ -system-libpng ..... 使用系統libpng庫
見 http://www.libpng.org/pub/png
-no-libmng ......... 不編譯MNG支持插件.
-qt-libmng ......... 編譯MNG支持插件.
+ -system-libmng ..... 使用系統的mng庫
參見 http://www.libmng.com
-no-libtiff ........ 不編譯tiff支持插件.
-qt-libtiff ........ 編譯tiff支持插件.
+ -system-libtiff .... 使用系統的libtiff庫
見 http://www.libtiff.org
-no-libjpeg ........ 不編譯jpeg支持插件庫
-qt-libjpeg ........ 編譯jpeg支持插件庫
+ -system-libjpeg .... 使用系統的jpeg支持庫
見 http://www.ijg.org
如下參數僅對qt for windows有效
-no-dsp ............ 不生成 VC++ .dsp 文檔.
* -dsp ...............生成 VC++ .dsp文檔, 須要有平臺標識符"win32-msvc".注意 qt4開始就不支持vc6.0了因此這兩個參數無效。
-no-vcproj ......... 不生成 VC++ .vcproj 文檔
* -vcproj ............ 生成 VC++ .vcproj 文檔, 須要平臺標識符"win32-msvc.net".也就是vs2003以上的編譯環境
-no-incredibuild-xge Do not add IncrediBuild XGE distribution commands to custom build steps.
+ -incredibuild-xge .. Add IncrediBuild XGE distribution commands to custom build steps. This will distribute MOC and UIC steps, and other custom buildsteps which are added to the INCREDIBUILD_XGE variable.
(The IncrediBuild distribution commands are only added to Visual Studio projects)
-no-plugin-manifests 插件不嵌入manifests.
* -plugin-manifests .. 插件嵌入manifests.
-no-qmake .......... 不編譯qmake
* -qmake ............. 編譯 qmake. 不建議 不編譯qmake
-dont-process ...... 不生成makefiles和project文檔. 比 -no-fast 參數優先級更高
* -process ........... 生成makefiles和project文檔.
-no-rtti ........... 不編譯運行時類型信息。
* -rtti .............. 編譯運行時類型信息。
//下面是對指令的支持,不解釋了
-no-mmx ............ Do not compile with use of MMX instructions
+ -mmx ............... Compile with use of MMX instructions
-no-3dnow .......... Do not compile
with use of 3DNOW instructions
+ -3dnow ............. Compile with use of 3DNOW instructions
-no-sse ............ Do not compile with use of SSE instructions
+ -sse ............... Compile with use of SSE instructions
-no-sse2 ........... Do not compile with use of SSE2 instructions
+ -sse2 .............. Compile with use of SSE2 instructions
+ -direct3d .......... 將Direct3D支持編譯進來。檢測不到direct3d sdk 就不支持
-no-openssl ........ Do not compile in OpenSSL support
+ -openssl ........... Compile in run-time OpenSSL support
-openssl-linked .... Compile in linked OpenSSL support
-no-dbus ........... Do not compile in D-Bus support
+ -dbus .............. Compile in D-Bus support and load libdbus-1 dynamically
-dbus-linked ....... Compile in D-Bus support and link to libdbus-1
-no-phonon ......... 不將 Phonon 模塊編譯進來
+ -phonon ............ 將 Phonon 模塊編譯進來 (若使用的規範的c++編譯器則會自動編譯Phonon模塊)
-no-phonon-backend . Do not compile the platform-specific Phonon backend-plu
gin
* -phonon-backend .... Compile in the platform-specific Phonon backend-plugin
-no-webkit ......... 不將webkit模塊編譯進來,編譯webkit很是耗時間。
+ -webkit ............ 將webkit模塊編譯進來 (若使用的規範的c++編譯器則會自動編譯WebKit模塊)
-no-scripttools .... Do not build the QtScriptTools module.
* -scripttools ....... Build the QtScriptTools module.
-arch ....... 外觀樣式.
有如下幾種 :
* windows
windowsce
boundschecker
generic
-no-style-尖括號裏包含上面的樣式。
4.完成了configure後就能夠接着運行:
D:/Qt/2009.03/qt> nmake
漫長的等待吧,該幹什麼幹什麼去吧,我大概花了6個半小時,呵呵,我是徹底編譯的,中間會出現一些warning,可有可無的,呵呵~
5.最後編譯完成後運行nmake confclean命令清除編譯過程當中的臨時文件,以節省空間,大概是4500M左右;
6. 將Qt路徑添加到VC編譯環境中,工具->選項->項目和解決方案->VC++目錄,在包含庫文件一欄添加:
QtGui4.lib;
QtCore4.lib;
另外補充一點若是你用Qt Creater開發的話,工程的目錄中不能有漢字,不然會編譯出錯的,還有就是有個集成Qt到VS的插件,那個插件目前只支持英文的VS2005,中文的會在啓動VS2005時出錯的!
http://blog.csdn.net/masonwu21/article/details/4770274