当前位置:   article > 正文

Qt Installer Framework打包基础_qt installer framework 脚本

qt installer framework 脚本

一、简介

Qt Installer Framework(简称QIF)提供了一组工具和实用程序来创建支持桌面Qt平台的安装程序,支持Linux, Microsoft WindowsmacOS操作系统。

二、操作步骤

1.编译可执行程序文件

这里以Visual Studio 的C++项目为例,步骤如下:

  1. 双击sln文件打开项目;
  2. 解决方案配置选择Release
  3. 工具栏-生成-重新生成解决方案;
  4. 生成成功后,根据输出窗口的信息,找到可执行程序。

2.创建IFW所需目录结构

以下是Qt Installer Framework打包所需的基本目录结构

AppDir
  |--config
  |    |--config.xml
  |--packages
       |--module1_dir
  	   |    |--data
       |    |    |--files
       |    |--meta
       |         |--package.xml
       |         |--installscript.qs
       |--module2_dir
       |...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • AppDir是根目录,名称可自定义;
  • config用于存放打包的全局配置文件;
  • packages目录是所有模块的父目录,其下的子目录分别对应各个模块;
  • 各个模块目录中都包含data目录,用于存放需要打包的文件;
  • 同时,模块目录也包含meta目录,用于存放该模块的配置文件。

3.把需要打包的文件放到data目录

在第一步已生成了应用的可执行文件并找到了其路径,现在可以把其中的YourApp.exeYourApp.libYourApp.exp文件都拷贝到AppDir/packages/module_dir/data目录下。然后,把应用依赖的其他动态库、配置文件和资源文件等文件按正确的目录结构拷贝到data目录下

4.使用windeployqt创建Qt库

打开命令行,输入以下命令并执行,就可生成Qt环境所需的文件:

windeployqt.exe  你的目录/AppDir/packages/module_dir/data/YourApp.exe 
  • 1

命令执行完后,会在data目录下看到Qt所需的动态库等文件。

5.编写config.xml

这里以IFW的示例startmenu为例,config.xml的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    <Name>Start Menu Shortcut Example</Name>
    <Version>1.0.0</Version>
    <Title>Start Menu Shortcut Example</Title>
    <Publisher>Qt-Project</Publisher>
    <!-- Directory name is used in component.xml -->
    <StartMenuDir>Qt Installer Framework Examples</StartMenuDir>
    <TargetDir>@HomeDir@/IfwExamples/startmenu</TargetDir>
</Installer>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • <Name>标签内的是应用名称
  • <Version>用于指定版本号;
  • <Title>是安装程序的标题栏内容;
  • <Publisher>是发布者的名称;
  • <StartMenuDir>用于指定应用在开始菜单的目录名;
  • <TargetDir>是应用的默认安装目录。

6.编写package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package>
    <DisplayName>README.txt</DisplayName>
    <Description>A README.txt, accessible through a start menu entry.</Description>
    <Version>1.0.0-1</Version>
    <ReleaseDate>2013-01-01</ReleaseDate>
    <Default>true</Default>
    <Script>installscript.qs</Script>
</Package>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

在安装程序中,有选择组件的页面,其中的内容对应的就是各个模块。
<DisplayName>指定的就是该模块在页面中显示的名称;
<Description>是模块的描述信息
<Version>是模块的版本号
<ReleaseDate>表示发布日期
<Default>设置是否默认勾选
<Script>用于指定控制安装该模块的脚本文件所在路径

7.编写installscript.qs

installscript.qs是用于控制模块安装的脚本,其中定义了很多全局变量和函数,这里也以startmenu的脚本为例:

function Component()
{
    this.createOperations = function()
    {
        var programFilesPath = installer.value("ProgramFilesDir");
        var shortcutDirPath = installer.value("DesktopDir");
        var shortcutPath = shortcutDirPath + "/MyApp.lnk";

        component.createOperations();

        if (installer.isUninstaller()) {
            // 不会在卸载操作中创建快捷方式
            return;
        }

        // 创建快捷方式
        var link = installer.guicreateShortcut(shortcutPath, "@TargetName@");
        link.description = "@TargetName@";
        link.iconPath = programFilesPath + "/MyApp/icon.ico";
        link.write();
    }
}

Component.prototype.createOperations = function()
{
    // call default implementation to actually install GDOsgCloudProject.exe!
    component.createOperations();

    if (systemInfo.productType === "windows") {
        component.addOperation("CreateShortcut", "@TargetDir@/GDOsgCloudProject.exe", "@StartMenuDir@/GDOsgCloudProject.lnk",
            "workingDirectory=@TargetDir@", "iconPath=%SystemRoot%/system32/SHELL32.dll",
            "iconId=2", "description=Run GDOsgCloudProject.exe");
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

其中,function Component()是组件的构造函数,其中执行了用户定义的一些操作,如:创建快捷方式等。

8.启动IFW打包

前面的所有步骤都完成后,就可以执行一下命令打包了。

binarycreator.exe -c config/config.xml -p packages install.exe -v
  • 1

其中,c参数是指定config.xml文件的路径,p参数用于指定packages目录的路径,这两个都可以是相对路径;install.exe是生成的安装包名称,可按自己的需求指定,默认在AppDir目录下生成;v参数表示输出日志信息。
IFW默认会同时生成maintenancetool.exe用于修复和卸载程序。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/170746
推荐阅读
相关标签
  

闽ICP备14008679号