欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

qt之InstallerFramework:程序打包

程序员文章站 2022-07-12 19:17:17
...

Qt installer framework

1. 创建安装包目录树

tutorial
├── config
│   └── config.xml
└── packages
    └── com.vendor.product
        ├── data
        │   └── installcontent.txt
        └── meta
            ├── installscript.qs
            ├── license.txt
            ├── package.xml
            └── page.ui

2. 创建配置文件

(即/tutorial/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 vendor</Publisher>
    <StartMenuDir>Super App</StartMenuDir> <!--windows开始菜单中的分组-->
    <TargetDir>@aaa@qq.com/InstallationDirectory</TargetDir> <!--默认安装位置-->
</Installer>

主要是修改 [1] -- <Titile> [2] -- <Name>

qt之InstallerFramework:程序打包

3. 创建安装包信息文件

(即/tutorial/packages/com.vendor.product/meta/package.xml)

<?xml version="1.0" encoding="UTF-8"?>
<Package>
    <DisplayName>The root component</DisplayName>
    <Description>Install this example.</Description>
    <Version>0.1.0-1</Version>
    <ReleaseDate>2010-09-21</ReleaseDate>
    <Licenses>
        <License name="Beer Public License Agreement" file="license.txt" />
    </Licenses>
    <Default>script</Default>
    <Script>installscript.qs</Script> <!--installscript.qs脚本定制安装过程-->
    <UserInterfaces>
        <UserInterface>page.ui</UserInterface> <!--界面资源文件-->
    </UserInterfaces>
</Package>

主要修改[1] -- <DisplayName> [2] -- <Description>

qt之InstallerFramework:程序打包

[1] – 具体的文件描述在/tutorial/packages/com.vendor.product/meta/license.txt

qt之InstallerFramework:程序打包

/tutorial/packages/com.vendor.product/meta/package.xmlinstallscript.qs示例

function Component()
{
    // constructor
    component.loaded.connect(this, Component.prototype.loaded);
    if (!installer.addWizardPage(component, "Page", QInstaller.TargetDirectory))
        console.log("Could not add the dynamic page.");
}

Component.prototype.isDefault = function()
{
    // select the component by default
    return true;
}

Component.prototype.createOperations = function()
{
    try {
        // call the base create operations function
        component.createOperations();
    } catch (e) {
        console.log(e);
    }
}

Component.prototype.loaded = function ()
{
    var page = gui.pageByObjectName("DynamicPage");
    if (page != null) {
        console.log("Connecting the dynamic page entered signal.");
        page.entered.connect(Component.prototype.dynamicPageEntered);
    }
}

Component.prototype.dynamicPageEntered = function ()
{
    var pageWidget = gui.pageWidgetByObjectName("DynamicPage");
    if (pageWidget != null) {
        console.log("Setting the widgets label text.")
        pageWidget.m_pageLabel.text = "This is a dynamically created page.";
    }
}

4. 创建安装内容

(即/tutorial/packages/com.vendor.product/data/installcontent.txt)

实际要打包的程序文件(.dll, .exe等)存放于该目录(data)下

5. 创建可执行文件

(当前目录在tutorial下)

../../bin/binarycreator -c config/config.xml -p packages YourInstaller

6. 实际操作

  • 将要打包的工程使用 release 模式编译
  • 使用ldd命令查找相关依赖,将依赖文件也置于同一文件下
  • 将release下的依赖文件以及可执行程序文件拷贝到data目录下
  • 使用binarycreator命令行直接生成安装包

参考链接

相关标签: 打包