打开ReadMe示例
使用组件脚本来向最终安装页添加打开ReadMe文件的复选框。

打开ReadMe演示如何使用Component()函数向安装完成页添加复选框,并在最终用户选择复选框时打开readme文件。
配置示例安装器
在config目录中的安装器配置文件,config.xml,指定了安装器中使用的文本和默认值
<Name>元素设置应用程序名称,并将其添加到页面名称和介绍文本中。<Version>元素设置应用程序版本号。<Title>元素设置安装器名称,并在标题栏中显示。<Publisher>元素设置软件的发布者(例如,在Windows控制面板中显示)。<StartMenuDir>元素设置Windows 开始菜单中产品的默认程序组名称。<TargetDir>元素设置默认目标目录位置,在当前用户家目录下的IfwExamples目录内部(因为它使用了预定义变量,@HomeDir@,作为值的部分)。有关更多信息,请参阅预定义变量.
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>Open Readme Example</Name>
<Version>1.0.0</Version>
<Title>Open Readme Example</Title>
<Publisher>Qt-Project</Publisher>
<StartMenuDir>Qt IFW Examples</StartMenuDir>
<TargetDir>@HomeDir@/IfwExamples/openreadme</TargetDir>
</Installer>创建示例包信息文件
在meta目录中的安装器包信息文件,package.xml,指定了可安装的组件
<DisplayName>元素设置组件的可读名称。<Description>元素设置组件的易读说明。<Version>元素设置组件的版本号。<ReleaseDate>元素设置此组件版本的发布日期。
<Default>元素设置为true以在安装器中预选中组件。<Script>元素指定要加载执行操作的JavaScript文件的文件名。<UserInterfaces>元素指定要使用的安装器页面(.ui文件)的文件名。
<?xml version="1.0" encoding="UTF-8"?>
<Package>
<DisplayName>Open readme</DisplayName>
<Description>Show checkbox asking whether to open Readme at the end</Description>
<Version>1.0.0-1</Version>
<ReleaseDate>2013-01-01</ReleaseDate>
<Default>true</Default>
<Script>installscript.qs</Script>
<UserInterfaces>
<UserInterface>readmecheckboxform.ui</UserInterface>
</UserInterfaces>
</Package>安装后打开文件
在installscript.qs中,我们在安装完成后使用Component()函数连接到installationFinishedPageIsShown信号,当最终用户点击完成(macOS上的完成)时连接到installationFinished信号。
function Component()
{
installer.installationFinished.connect(this, Component.prototype.installationFinishedPageIsShown);
installer.finishButtonClicked.connect(this, Component.prototype.installationFinished);
}我们调用component::createOperations()函数以覆盖创建操作的自定义方法
Component.prototype.createOperations = function()
{
component.createOperations();
}如果安装成功,我们调用installer::addWizardPageItem()函数以将最后的安装器页面替换为包含打开ReadMe复选框的自定义页面
Component.prototype.installationFinishedPageIsShown = function()
{
try {
if (installer.isInstaller() && installer.status == QInstaller.Success) {
installer.addWizardPageItem( component, "ReadMeCheckBoxForm", QInstaller.InstallationFinished );
}
} catch(e) {
console.log(e);
}
}默认将 readMeCheckBox 设置为 checked,并使用 QDesktopServices::openURL() 函数打开说明文件
Component.prototype.installationFinished = function()
{
try {
if (installer.isInstaller() && installer.status == QInstaller.Success) {
var checkboxForm = component.userInterface( "ReadMeCheckBoxForm" );
if (checkboxForm && checkboxForm.readMeCheckBox.checked) {
QDesktopServices.openUrl("file:///" + installer.value("TargetDir") + "/README.txt");
}
}
} catch(e) {
console.log(e);
}
}生成示例安装程序
要创建示例安装程序,请在命令行中切换到示例源目录,并输入以下命令
- 在 Windows 上
..\..\bin\binarycreator.exe -c config\config.xml -p packages installer.exe
- 在 Linux 或 macOS 上
../../bin/binarycreator -c config/config.xml -p packages installer
这将在当前目录创建安装程序。
文件
- openreadme/config/config.xml
- openreadme/openreadme.pro
- openreadme/packages/or.qtproject.ifw.example.openreadme/data/README.txt
- openreadme/packages/or.qtproject.ifw.example.openreadme/meta/installscript.qs
- openreadme/packages/or.qtproject.ifw.example.openreadme/meta/package.xml
- openreadme/packages/or.qtproject.ifw.example.openreadme/meta/readmecheckboxform.ui
©2021 Qt 公司有限公司版权所有。本文件中的文档贡献属于其各自的版权所有者。提供的文档是按照由自由软件基金会发布的 GNU自由文档许可证1.3版 的条款授权的。Qt 公司、Qt 及其各自的标志是芬兰和/或其他国家的 The Qt Company Ltd 的商标。所有其他商标均为各自所有者的财产。