1. 程式人生 > >win7平臺下QT軟體的打包與釋出(部署與安裝)

win7平臺下QT軟體的打包與釋出(部署與安裝)

軟體編寫除錯好之後最重要的就是打包和釋出,這樣軟體才好傳播。

qt軟體的打包釋出一個難點是必備dll檔案的識別。不少日誌說用dependencyWalker,今天我試了一下發現查詢dll不完全,比如辨識不了qwindows.dll(會報錯could not find or load the qt platform plugin windows)。並且還要自己手動新增不是很方便。一番查詢後發現qt內建一個現成的dll依賴性工具windeployqt十分好用,該工具在qt的bin/目錄下。

參考官方文件:http://doc.qt.io/qt-5/windows-deployment.html#application-dependencies

第一步是新增qt的bin/目錄進系統path變數。很簡單,在系統屬性裡設定,新增D:\Qt\5.4\msvc2010_opengl\bin;到系統path環境變數。(qt安裝目錄不盡相同)

第二部,在任意目錄新建資料夾,把編譯完成後的qt exe可執行程式拷貝過去。從命令列模式進入該資料夾,執行語句windeployqt xxxx.exe. 之後該工具會分析程式依賴性,自動新增必要dll檔案至該目錄。執行時命令列提示如下

D:\TVS\Qt\LGTVSerialControl>windeployqt terminal.exe --release
D:\TVS\Qt\LGTVSerialControl\terminal.exe 32 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Direct dependencies: Qt5Core Qt5Gui Qt5SerialPort Qt5Widgets
All dependencies   : Qt5Core Qt5Gui Qt5SerialPort Qt5Widgets
To be deployed     : Qt5Core Qt5Gui Qt5SerialPort Qt5Svg Qt5Widgets
Warning: Cannot find Visual Studio installation directory, VCINSTALLDIR is not s
et.
Updating icuin53.dll.
Updating icuuc53.dll.
Updating icudt53.dll.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5SerialPort.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Creating directory iconengines.
Updating qsvgicon.dll.
Creating directory imageformats.
Updating qdds.dll.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjp2.dll.
Updating qjpeg.dll.
Updating qmng.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory platforms.
Updating qwindows.dll.
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_de.qm...
Creating qt_fi.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...

D:\TVS\Qt\LGTVSerialControl>

這樣必要的庫檔案就自動新增完畢。

後面就是打包形成安裝包了。QT官方推薦了3種軟體(https://qt-project.org/wiki/BuildingQtInstallers+&cd=1&hl=en&ct=clnk&gl=us),這裡舉例第二種軟體NSIS說明使用方法。

下載安裝NSIS。安裝後啟動介面如下:


最簡單的方法是使用第二個選項Installer based on zip file(由zip檔案構建安裝包)

把剛才使用了windeployqt的整個目錄打包成zip檔案,用NSIS載入該zip檔案,設定好預設安裝目錄,點generate就可以打包成安裝包了。