Qt Installer Framework动态页面安装程序示例

Dynamic Page Installer Example

动态页面安装程序示例

Using a component script and dynamic pages to build an installer.

使用组件脚本和动态页面构建安装程序。

Dynamic Page Installer illustrates how to use the component.loaded.connect() function to load custom installer pages (.ui) instead of using the default installer pages and how to add functionality to the pages.

动态页面安装程序说明了如何使用component.load.connect()函数加载自定义安装程序页面(.ui),而不是使用默认安装程序页面,以及如何向页面添加功能。

The Select Installation Type page contains icons that are added to a Qt resource file (.qrc) for delivery with the installer.

“选择安装类型”页面包含添加到Qt资源文件(.qrc)中的图标,以便与安装程序一起交付。

Configuring the Example Installer
配置示例安装程序

The installer configuration file, config.xml, in the config directory specifies the text and default values used in the installer:

config目录中的安装程序配置文件config.xml指定了安装程序中使用的文本和默认值:

  • The <Name> element sets the application name and adds it to the page name and introduction text.
  • <Name>元素设置应用程序名称并将其添加到页面名称和介绍文本中。
  • The <Version> element sets the application version number.
  • <Version>元素设置应用程序版本号。
  • The <Title> element sets the installer name and displays it on the title bar.
  • <Title>元素设置安装程序名称并将其显示在标题栏上。
  • 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 the default target directory location to be within the IfwExamples directory in the home directory of the current user (because it uses the pre-existing variable , @HomeDir@, as part of the value). For more information, see Predefined Variables.
  • ​<TargetDir>元素将默认目标目录位置设置为当前用户主目录中的IfwExamples目录内(因为它使用预先存在的变量@HomeDir@作为值的一部分)。有关详细信息,请参见预定义变量。
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    <Name>Dynamic Page Installer Example</Name>
    <Version>1.0.0</Version>
    <Title>Dynamic Page Installer Example</Title>
    <Publisher>Qt-Project</Publisher>
    <StartMenuDir>Qt IFW Examples</StartMenuDir>
    <TargetDir>@HomeDir@/IfwExamples/dynamicpage</TargetDir>
</Installer>
Creating the Example Package Information File
创建示例包信息文件

The installer package information file, package.xml, in the meta directory specifies the components that are available for installation:

meta 目录中的安装程序包信息文件package.xml指定了可用于安装的组件:

  • The <DisplayName> element sets the human-readable name of the component.
  • <DisplayName>元素设置组件的人类可读名称。
  • The <Description> element sets the human-readable description of the component.
  • <Description>元素设置组件的人类可读描述。
  • The <Version> element sets the version number of the component.
  • <Version>元素设置组件的版本号。
  • The <ReleaseDate> element sets the date of release for this component version.
  • <ReleaseDate>元素设置此组件版本的发布日期。
  • The <Script> element specifies the file name of the JavaScript file that is loaded to perform operations.
  • <Script>元素指定加载以执行操作的JavaScript文件的文件名。
  • The <UserInterfaces> element specifies the file names of the installer pages (.ui files) to use.
  • <UserInterfaces>元素指定要使用的安装程序页面(.ui文件)的文件名。
  • The <Name> element provides domain-like identification for the component.
  • <Name>元素为组件提供类域标识。
<?xml version="1.0"?>
<Package>
    <DisplayName>Dynamic page installer example</DisplayName>
    <Description>Can be used as reference on how to build installer independent of predefined installer pages.</Description>
    <Version>1.0.0</Version>
    <ReleaseDate>2014-04-07</ReleaseDate>
    <Script>installscript.js</Script>
    <UserInterfaces>
        <UserInterface>targetwidget.ui</UserInterface>
        <UserInterface>installationwidget.ui</UserInterface>
        <UserInterface>licensewidget.ui</UserInterface>
        <UserInterface>readytoinstallwidget.ui</UserInterface>
    </UserInterfaces>
    <Name>org.qtproject.ifw.example.dynamicpage</Name>
</Package>

This installer contains three components that each have their own package information file with slightly different contents.

此安装程序包含三个组件,每个组件都有自己的包信息文件,内容略有不同。

Creating Dynamic Pages
创建动态页面

In installscript.js, we create the installer pages and add functionality to them.

在installscript.js中,我们创建安装程序页面并为其添加功能。

Qt Installer Framework calls the constructors of all scripts. When all the constructors are finished and all UI files are loaded, a loaded signal is emitted for each component.

Qt安装程序框架调用所有脚本的构造函数。当所有构造函数都完成并且所有UI文件都加载完毕时,每个组件都会发出loaded 信号。

To create an installer page, we have to wait for the loaded signal that tells us that the UI file has been loaded:

要创建安装程序页面,我们必须等待加载的信号,该信号告诉我们UI文件已加载:

component.loaded.connect(this, Component.prototype.installerLoaded);

We hide the default pages by setting their visibility to false:

我们通过将默认页面的可见性设置为false来隐藏它们:

installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);
installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);
installer.setDefaultPageVisible(QInstaller.LicenseCheck, false);
if (systemInfo.productType === "windows")
    installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false);
installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false);

We use the loaded function that we connected earlier to add functionality to the dynamic installer pages:

我们使用之前连接的loaded 函数为动态安装程序页面添加功能:

Component.prototype.installerLoaded = function () {
    if (installer.addWizardPage(component, "TargetWidget", QInstaller.TargetDirectory)) {
        var widget = gui.pageWidgetByObjectName("DynamicTargetWidget");
        if (widget != null) {
            widget.targetChooser.clicked.connect(this, Component.prototype.chooseTarget);
            widget.targetDirectory.textChanged.connect(this, Component.prototype.targetChanged);

            widget.windowTitle = "Installation Folder";
            widget.targetDirectory.text = Dir.toNativeSparator(installer.value("TargetDir"));
        }
    }

    if (installer.addWizardPage(component, "InstallationWidget", QInstaller.ComponentSelection)) {
        var widget = gui.pageWidgetByObjectName("DynamicInstallationWidget");
        if (widget != null) {
            widget.customInstall.toggled.connect(this, Component.prototype.customInstallToggled);
            widget.defaultInstall.toggled.connect(this, Component.prototype.defaultInstallToggled);
            widget.completeInstall.toggled.connect(this, Component.prototype.completeInstallToggled);

            widget.defaultInstall.checked = true;
            widget.windowTitle = "Select Installation Type";
        }
    ...

installer::addWizardPage() registers a new page to the installer. gui::pageWidgetByObjectName() is then used to retrieve the root widget of the new page, with its name being "Dynamic" + the object name of the root widget as set in the .ui file.

installer::addWizardPage()向安装程序注册一个新页面。gui::pageWidgetByObjectName()然后用于检索新页面的根小部件,其名称为“Dynamic”+.ui文件中设置的根widget对象名称。

Generating the Example Installer
生成示例安装程序

To create the example installer, switch to the example source directory on the command line and enter the following command:

要创建示例安装程序,请在命令行上切换到示例源代码目录,然后输入以下命令:

  • On Windows:
    ..\..\bin\binarycreator.exe -c config\config.xml -r resources/additional.qrc -p packages installer.exe
    
  • On Linux or macOS:
    ../../bin/binarycreator -c config/config.xml -r resources/additional.qrc -p packages installer
    

Because the installer uses additional resources, you must give the -r option and specify the path to the Qt resource file that contains the resources. The installer is created in the current directory.

由于安装程序使用了额外的资源,必须提供-r选项并指定包含这些资源的Qt资源文件的路径。安装程序是在当前目录中创建的。

Files:

Images:

© 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、付费专栏及课程。

余额充值