1
<location-of-ifw>\binarycreator.exe --offline-only -t <location-of-ifw>\installerbase.exe -p <package_directory> -c <config_directory>\<config_file> <installer_name>

binarycreator.exe可以在Qt的安装目录下找到Tools/QtInstallerFramework
需要有一个conf.xml作为配置,在package_directory目录可以放置对应的程序可执行文件和安装时进行配置运行的一些脚本实现快捷方式的创建等操作。

示例目录结构

1
2
3
4
├─config └─config.xml └─packages └─com.example.app ├─data └─meta
  1. 对应config目录下编写配置文件config.xml
  2. packages文件夹下对应软件包,一个独立软件一个目录,我们的软件只有一个目录因此只有com.example.app一个文件夹,其中data目录存放二进制文件,meta目录用于存放配置文件和脚本

依次分析配置文件
config/config.xml是对整个安装包的概述

1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?> <Installer> <Name>Your app name</Name> <Version>1.0.0</Version> <Title>App installer</Title> <Publisher>Vendor</Publisher> <StartMenuDir>Menu name</StartMenuDir> <TargetDir>@HomeDir@/Menuname/App name</TargetDir> </Installer>

然后把软件依赖拷贝到packages/<package name>/data目录下,包括所有的二进制依赖
然后在packages/<package name>/meta下放入三个文件

  • license.txt —— 软件的License文本,这是个文本可以根据实际随意编写
  • package.xml —— 软件包的定义文件
  • installscript.qs —— 这是Qt的一个脚本用来实现创建快捷方式等操作

先来看package.xml这个文件

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?> <Package> <DisplayName>Package name</DisplayName> <Description>Package discription</Description> <Version>1.0.1</Version> <ReleaseDate>2025-01-06</ReleaseDate> <Licenses> <License name="<Your license name>" file="license.txt or other file" /> </Licenses> <Default>true</Default> <Script>installscript.qs</Script> </Package>

里面不同的字段规定了软件包对应的License、安装执行用的脚本等信息。

最后再来看installscript.qs,当中设定了一些菜单创建和桌面快捷方式创建的功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function Component() { // default constructor } Component.prototype.createOperations = function() { component.createOperations(); if (systemInfo.productType === "windows") { component.addOperation("CreateShortcut", "@TargetDir@/App.exe", "@StartMenuDir@/App.lnk", "workingDirectory=@TargetDir@"); try { var userProfile = installer.environmentVariable("USERPROFILE"); installer.setValue("UserProfile", userProfile); component.addOperation("CreateShortcut", "@TargetDir@/App.exe", "@UserProfile@/Desktop/App.lnk", "workingDirectory=@TargetDir@"); } catch(e) { print(e); } } }

参考链接
Qt官方教程
Qt官方案例
创建快捷方式——StackOverflow