Qt Installer Framework 教程:创建安装程序

Tutorial: Creating an Installer

教程:创建安装程序

This tutorial describes how to create a simple installer for a small project:

本教程介绍如何为小型项目创建简单的安装程序:

This section describes the following tasks that you must carry out to create the installer:

本节介绍创建安装程序必须执行的以下任务:

1.Create a package directory that will have all the configuration files and installable packages.

1.创建一个包含所有配置文件和可安装包的package目录。

2.Create a configuration file that has information about how to build the installer binaries and online repositories.

2.创建一个配置文件,其中包含有关如何构建安装程序二进制文件和在线存储库的信息。

3.Create a package information file that has information about the installable components.

3.创建一个包信息文件,其中包含有关可安装组件的信息。

4.Create installer content and copy it to the package directory.

4.创建安装程序内容并将其复制到包目录。

5.Use the binarycreator tool to create the installer.

5.使用binarycreator工具创建安装程序。

To create the installer pages, use the information set in the configuration and package information file.

要创建安装程序页面,请使用配置和包信息文件中设置的信息。

You can find the example files in the examples\tutorial directory in the Qt Installer Framework repository.

可以在Qt Installer Framework存储库的examples\tutorial目录中找到示例文件。

Creating a Package Directory

创建包目录

Create a directory structure that reflects the design of the installer and allows for future extension. The directory must contain subdirectories called config and packages.

创建一个反映安装程序设计并允许未来扩展的目录结构。该目录必须包含名为config和packages的子目录。

For more information about the package directory, see Package Directory.

​有关包目录的更多信息,请参阅包目录。

Creating a Configuration File

创建配置文件

In the config directory, create a file called config.xml with the following contents:

在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>
    <TargetDir>@HomeDir@/InstallationDirectory</TargetDir>
</Installer>

The configuration file includes the following information for the introduction page:

配置文件包括介绍页面的以下信息:

  • The <Title> element sets the installer name and displays it on the title bar (1).
  • <Title>元素设置安装程序名称并将其显示在标题栏(1)上。
  • The <Name> element sets the application name and adds it to the page number and introduction text (2).
  • <Name>元素设置应用程序名称并将其添加到页码和介绍文本(2)中。

The other elements customize the behavior of the installer:

其他元素自定义安装程序的行为:

  • The <Version> element sets the application version number.
  • <Version>元素设置应用程序版本号。
  • The <Publisher> element sets the publisher of the software (as shown in the Windows Control Panel, for example).
  • <Publisher>元素设置软件的发布者(例如,如Windows控制面板所示)。
  • The <StartMenuDir> element sets the name of the default program group for the product in the Windows Start menu.
  • <StartMenuDir>元素在Windows“开始”菜单中设置产品的默认程序组的名称。
  • The <TargetDir> element sets and displays InstallationDirectory in the home directory of the current user as the default target directory displayed to users (because it uses the predefined variable @HomeDir@ as part of the value). For more information, see Predefined Variables.
  • ​<TargetDir>元素将当前用户主目录中的InstallationDirectory设置并显示为显示给用户的默认目标目录(因为它使用预定义变量@HomeDir@作为值的一部分)。有关详细信息,请参见预定义变量。

For more information about the configuration file format and the available elements, see Configuration File.

​有关配置文件格式和可用元素的更多信息,请参阅配置文件。

Creating a Package Information File

创建包信息文件

In this easy scenario, the installer handles only one component, com.vendor.product. To give the installer information about the component, create a file called package.xml with the following contents and place it in the meta directory:

在这个简单的场景中,安装程序只处理一个组件com.vendor.product。要向安装程序提供有关组件的信息,请创建一个名为package.xml的文件,其中包含以下内容,并将其放置在meta 目录中:

<?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>
    <UserInterfaces>
        <UserInterface>page.ui</UserInterface>
    </UserInterfaces>
</Package>

Below is a more detailed description of the elements in the example file. For more information about the package information file, see Package Information File Syntax.

​下面是对示例文件中元素的更详细描述。有关包信息文件的更多信息,请参阅包信息文件语法。

Specifying Component Information

指定组件信息

The component selection page displays information from the following elements:

组件选择页面显示以下元素的信息:

  • The <DisplayName> element sets the name of the component in the component list (1).
  • <DisplayName>元素在组件列表(1)中设置组件的名称。
  • The <Description> element sets and displays text based on the selected component (2).
  • <Description>元素根据所选组件(2)设置和显示文本。

Specifying Installer Version

指定安装程序版本

The <Version> element offers updates to users when they become available.

<Version>元素在更新可用时向用户提供更新。

Adding Licenses

添加许可证

The <License> element sets the name of the file, which has the license agreement text (1). The license check page displays this license text.

<License>元素设置文件的名称,其中包含许可协议文本(1)。许可证检查页面显示此许可证文本。

Selecting Default Contents

选择默认内容

The <Default> element specifies whether the selected component is a default value. The value true sets the component as selected. This example uses the value script to resolve the value during runtime. The <Script> element sets the name of the JavaScript script file, installscript.qs.

<Default>元素指定所选组件是否为默认值。值true将组件设置为选定状态。此示例使用值脚本在运行时解析值。<Script>元素设置JavaScript脚本文件的名称installscript.qs。

Creating Installer Content

创建安装程序内容

The data directory of a component can store content available for installation. As there is only one component, place the data in the packages/com.vendor.product/data directory. The example already has a file for testing purposes, but you can place basically any files in the directory.

组件的data目录可以存储可用于安装的内容。由于只有一个组件,请将数据放在packages/com.vendor.product/data目录中。该示例已经有一个用于测试的文件,但基本上可以将任何文件放置在该目录中。

For more information about packaging rules and options, see Data Directory.

​有关打包规则和选项的更多信息,请参阅数据目录。

Creating the Installer Binary

创建安装程序二进制文件

You are now ready to create your first installer. Switch to the examples\tutorial directory on the command line. To create an installer called YourInstaller.exe that has the packages identified by com.vendor.product, enter the following command:

现在,已准备好创建第一个安装程序。切换到命令行上的examples\tutorial目录。要创建名为YourInstaller.exe的安装程序,其中包含由com.vendor.product标识的包,请输入以下命令:

  • On Windows:
    ..\..\bin\binarycreator.exe -c config\config.xml -p packages YourInstaller.exe
    
  • On Linux or macOS:
    ../../bin/binarycreator -c config/config.xml -p packages YourInstaller
    

Qt Installer Framework creates the installer in the current directory and you can deliver it to end users.

Qt Installer Framework在当前目录中创建安装程序,可以将其交付给最终用户。

For more information about using the binarycreator tool, see binarycreator.

​有关使用binarycreator工具的更多信息,请参阅binarycreator。

Note: If an error message appears when you run the tutorial installer, check that you used a statically built Qt to create the installer. For more information, see Configuring Qt.


注意:如果在运行教程安装程序时出现错误消息,请检查是否使用了静态构建的Qt来创建安装程序。有关更多信息,请参阅配置Qt。

Specifying SettingsCreating Installers

© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. The Qt Company, Qt and their respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值