用QT Installer Framework打包exe文件的相关步骤(Windows)

开始学习用qt installer framework打包qt windows软件。相关步骤如下,以作记录。

1. 下载安装Qt Installer Framework

https://download.qt.io/official_releases/qt-installer-framework/

2. 为编译的exe文件添加icon

2.1. 在Qt工程目录下新建txt文本,命名为后缀.rc文件。例如res.rc

2.2. 在res.rc中,添加一行

IDI_ICON   ICON    DISCARDABLE     "icon.ico"

记得将icon.ico文件放到与.rc同文件夹下

2.3. 打开.pro工程,在.pro文件内加入命令行

RC_FILE = res.rc

2.4 重新编译即可

https://jingyan.baidu.com/article/90808022f4afc9fd91c80f2f.html

3. 用Qt Windeploy工具打包exe文件。

因为直接编译的release文件不包含qt核心文件,需要用Qt Windeploy进行打包。

3.1 运行MinGW。例如我打包64位,则用MinGW 7.3.0 64-bit

3.2 输入命令 windeployqt <exe文件路径>

4. 使用Qt Installer Framework打包生成Windows安装程序

4.1. 在Qt-Installer安装文件的bin目录下创建文件夹结构。

4.1.1 config文件夹下包含config.xml配置文件

4.1.2 package下包含产品文件夹

com.company.productname

4.1.3 产品文件夹包含data及meta

data放置打包的生成的所有文件及相关dll文件

meta存放qs,license及package等配置文件

4.2 将用windeployqt生成的打包文件及添加的dll文件全部复制到Qt-Installer安装文件的data目录下。

5 编辑Qt installer相关配置文件

5.1 config.xml示例

<?xml version="1.0"?>
<Installer>
	<Name>Your Product</Name>
	<Version>1.0.0</Version>
	<Title>Your Title</Title>
	<Publisher>Your Publisher</Publisher>
	<ProductUrl>Your Link</ProductUrl>
	<InstallerWindowIcon>installericon</InstallerWindowIcon>
	<InstallerApplicationIcon>installericon</InstallerApplicationIcon>
	<Logo>logo.png</Logo>
	<Watermark>watermark.png</Watermark>
	<RunProgram></RunProgram>
	<RunProgramArguments></RunProgramArguments>
	<RunProgramDescription></RunProgramDescription>
	<WizardShowPageList>false</WizardShowPageList>
	<StartMenuDir>PhotoEffects</StartMenuDir>
	<TargetDir>@HomeDir@/PhotoEffects</TargetDir>
	<AdminTargetDir>@rootDir@/PhotoEffects</AdminTargetDir>
</Installer>

5.2 package.xml示例

<?xml version="1.0"?>
<Package>
	<DisplayName>Your Name</DisplayName>
	<Description>Your Description</Description>
	<Version>1.0.0</Version>
	<ReleaseDate>2020-02-18</ReleaseDate>
	<Name>com.company.productname</Name>
	<Default>true</Default>
	<Licenses>
		<License name="License Agreement" file="license.txt" />
	</Licenses>
	<Script>installscript.qs</Script>
</Package>

5.3 installscript.qs 示例

function Component()
{
    // default constructor    	
}



Component.prototype.createOperations = function ()
{
    component.createOperations();
    if (installer.value("os") === "win") {

    component.addOperation( "CreateShortcut",
                            "@TargetDir@/Appname.exe",
                            "@StartMenuDir@/Appname.lnk", "-param", 
                            "workingDirectory=@TargetDir@",  
                            "iconPath=@TargetDir@/Appname.exe","iconId=0");

	component.addOperation("CreateShortcut", 
                            "@TargetDir@/Appname.exe",// target
                            "@DesktopDir@/Appname.lnk",// link-path
                            "workingDirectory=@TargetDir@",// working-dir
                            "iconPath=@TargetDir@/Appname.exe", "iconId=0",// icon
                            "description=Start Appname");// description

	}
}

}

注意componet.addOperation用于添加快捷方式

6 运行命令行进行打包

binarycreator.exe -c path\config\config.xml -p path\packages new.exe -v

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值