使用Qt Installer Framework生成安装包

阅读数:209 评论数:0

跳转到新版页面

分类

C/C++

正文

一、基本使用

1、从Qt官方网站下载并安装Qt installer Framework

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

2、构建你的应用程序

qmake
make

可以使用windeployqt工具将应用程序依赖的dll文件复制到应用程序目录下

windeployqt path/to/your/app.exe

3、创建安装项目结构

installer/
├── config/
│   └── config.xml
└── packages/
    └── com.yourcompany.yourapp/
        ├── meta/
        │   └── package.xml
        └── data/
            └── [your application files]

4、编写config.xml

config/ 目录下创建 config.xml,定义安装程序的基本信息:

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    <Name>Your Application</Name>
    <Version>1.0.0</Version>
    <Title>Your Application Installer</Title>
    <Publisher>Your Company</Publisher>
    <StartMenuDir>Your Application</StartMenuDir>
    <TargetDir>@HomeDir@/YourApplication</TargetDir>
</Installer>

5、创建包定义

packages/com.yourcompany.yourapp/meta/ 目录下创建 package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package>
    <DisplayName>Your Application</DisplayName>
    <Description>This is your application.</Description>
    <Version>1.0.0</Version>
    <ReleaseDate>2024-01-01</ReleaseDate>
    <Default>true</Default>
    <Script>installscript.qs</Script>
</Package>

6、准备应用程序文件

将构建生成的应用程序文件(如可执行文件、库、资源文件等)放入 packages/com.yourcompany.yourapp/data/ 目录中。

7、生成安装程序

binarycreator -c config/config.xml -p packages MyInstaller

二、生成桌面快捷方式和卸载

1、在package.xml中指定脚本

<Package>
    ...
    <Script>installscript.qs</Script>
</Package>

2、编写脚本

function Component() {}

Component.prototype.createOperations = function() {
    // 默认安装操作
    component.createOperations();

    // 创建快捷方式的操作
    component.addOperation("CreateShortcut", "@TargetDir@/maifodor-qt32-qmake.exe",
                           "@HomeDir@/Desktop/maifodor.lnk",
                           "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/maifodor.ico");

    component.addOperation("CreateShortcut", "@TargetDir@/maifodor-qt32-qmake.exe",
                           "@StartMenuDir@/maifodor.lnk",
                           "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/maifodor.ico");
}

Component.prototype.createUninstallOperations = function() {
    // 删除快捷方式
    component.addOperation("Delete", "@HomeDir@/Desktop/maifodor.lnk");
    component.addOperation("Delete", "@StartMenuDir@/maifodor.lnk");

    // 删除安装目录及其所有内容
    component.addOperation("Delete", "@TargetDir@", "force=true");
}



相关推荐