本章介紹把Qt開發(fā)的程序打包成安裝包的方法,程序打包成install.exe,可雙擊安裝,有默認安裝路徑,也可以選擇安裝目錄,自動生成桌面快捷方式和開始菜單選項,可以在操作系統(tǒng)–>設(shè)置–>應(yīng)用程序里看到,可卸載。
資源下載
需要的資源和目錄結(jié)構(gòu)已經(jīng)打包上傳,下載地址:https://download.csdn.net/download/weixin_40355471/87087830?spm=1001.2014.3001.5503
打包前準備
1、QT程序發(fā)布
QT程序先發(fā)布在一個文件夾里,QT程序發(fā)布方法參考:Qt發(fā)布軟件,windows和linux系統(tǒng)。
2、安裝Qt程序發(fā)布依賴包:QtInstallerFramework-win-x86.exe
打包步驟
1、將需要打包的程序文件夾放到 install\packages\org.qtproject.ifw.example\data。
2、修改 install/config/config.xml,是XML配置文件,字段含義見備注。
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>testSetup測試程序</Name><!-- 軟件名稱 -->
<Version>1.0.0</Version> <!--軟件版本號 -->
<Title>testSetup測試程序安裝向?qū)?span id="n5n3t3z" class="token tag"></Title><!-- 軟件安裝窗口顯示標題 -->
<Publisher>chw</Publisher> <!-- 發(fā)布者 -->
<!-- Directory name is used in component.xml -->
<StartMenuDir>testSetup測試程序</StartMenuDir> <!-- 要生成的windows開始菜單目錄 -->
<TargetDir>@HomeDir@/testSetup</TargetDir><!-- 默認安裝路徑 -->
</Installer>
3、修改 install/packages/org.qtproject.ifw.example/meta/installscript.qs。
這里創(chuàng)建桌面快捷方式和開始菜單
function Component()
{
// default constructor
}
Component.prototype.createOperations = function()
{
// call default implementation to actually install README.txt!
component.createOperations();
//appName.exe 為主程序名字,根據(jù)實際進行修改
if (systemInfo.productType === "windows") {
//創(chuàng)建開始菜單快捷方式
component.addOperation("CreateShortcut", "@TargetDir@/testSetup/testSetup.exe", "@StartMenuDir@/testSetup.lnk",
"workingDirectory=@TargetDir@/testSetup");
//創(chuàng)建桌面快捷方式
component.addOperation("CreateShortcut", "@TargetDir@/testSetup/testSetup.exe", "@DesktopDir@/testSetup.lnk",
"workingDirectory=@TargetDir@/testSetup");
}
}
4、生成安裝腳本.bat(install同級目錄),執(zhí)行成功后會在install/目錄下生成install.exe,即安裝包。
需要配置Qt Installer Framework的安裝目錄
rem @echo off
::binarycreator所在路徑需要根據(jù)實際情況即Qt Installer Framework安裝路徑下的bin目錄
SET PATH=%PATH%;C:\Qt\QtIFW-3.2.2\bin
::設(shè)置打包文件夾路徑(該路徑下包含config和packages兩個子文件夾)
set PACK_INSTALL_PATH=%cd%\install
echo 切換路徑到%PACK_INSTALL_PATH%
::切換路徑到安裝打包路徑
cd %PACK_INSTALL_PATH%
echo 生成安裝包
binarycreator.exe -c config/config.xml -p packages install.exe -v
echo **************************生成安裝包結(jié)束***************************
cd %~dp0
rem rd /s /q ..\compline
pause
安裝包安裝效果
選擇安裝目錄
選擇組建
創(chuàng)建開始菜單
開始安裝
桌面快捷方式
開始菜單
運行程序文章來源:http://www.zghlxwxcb.cn/news/detail-408297.html
系統(tǒng)設(shè)置菜單可查,可以修改或卸載程序
PS:
1、在安裝目錄里生成maintenancetool.exe文件,雙擊可以添加或移除組建、卸載程序等。
2、配置文件里的@HomeDir@是當前windows登錄用戶的家目錄。
3、配置文件里的@TargetDir@是程序的安裝目錄。文章來源地址http://www.zghlxwxcb.cn/news/detail-408297.html
到了這里,關(guān)于Qt程序打包成安裝包exe的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!