组件脚本

对于每个组件,您可以指定一个脚本,来准备要由安装程序执行的操作。脚本格式必须与QJSEngine兼容。

构造

脚本必须包含安装程序在加载脚本时创建的Component对象。 因此,脚本必须至少包含Component()函数,该函数执行初始化,例如将页面放置在正确的位置或连接信号和槽。

以下代码片段将ErrorPage页面(这是从errorpage.ui加载的用户界面文件的类名),放置在准备安装页面的前面,并将其完整性设置为false。

function Component()
{// Add a user interface file called ErrorPage, which should not be completeinstaller.addWizardPage( component, "ErrorPage", QInstaller.ReadyForInstallation );component.userInterface( "ErrorPage" ).complete = false;
}

有关更多信息,请参见installer::addWizardPage()和 component::userInterface()的文档。

安装钩子

您可以在脚本中添加以下钩子方法:

方法 描述
Component.prototype.retranslateUi 当安装程序的语言更改时调用。
Component.prototype.createOperations 见component::createOperations()。
Component.prototype.createOperationsForArchive 见component::createOperationsForArchive().
Component.prototype.createOperationsForPath 见component::createOperationsForPath().

全局变量

安装程序将以下符号放入脚本空间:

符号 描述
installer 引用组件的QInstaller
component 引用组件的Component

消息框

您可以使用以下静态成员函数从脚本中显示QMessageBox:
> QMessageBox::critical()
> QMessageBox::information()
> QMessageBox::question()
> QMessageBox::warning()

为了方便起见,可以通过QMessageBox.Ok,QMessageBox.Open等使QMessageBox::StandardButton可用。

向组件添加操作

例如,在拷贝文件或更新文件内容时,你可能需要在提取内容后添加自定义操作。您可以在脚本中使用component::addOperation(),来创建并添加更新操作到安装中。如果要运行要求管理员权限的操作,请改用component::addElevatedOperation()。

操作需要在实际安装步骤之前添加。覆盖component::createOperations(),以注册组件的自定义操作。

每个操作都有一个唯一的键,用于识别的,且最多可以包含五个参数。在参数值中,可以使用通过installer::setValue()设置的变量值。有关更多信息,请参见预定义变量章节。

有关所有可用操作的总结,请参见操作章节。

注册自定义操作

您可以在安装程序中注册自定义安装操作,通过派生KDUpdater::UpdateOperation类。 以下代码显示了必须实现的方法:

#include <UpdateOperation>class CustomOperation : public KDUpdater::UpdateOperation
{
public:CustomOperation(){setName( "CustomOperation" );}void backup(){// do whatever is needed to restore the state in undoOperation()}bool performOperation(){const QStringList args = arguments();// do whatever is needed to do for the given argumentsbool success = ...;return success;}void undoOperation(){// restore the previous state, as saved in backup()}bool testOperation(){// currently unusedreturn true;}CustomOperation* clone() const{return new CustomOperation;}QDomDocument toXml(){// automatically adds the operation's arguments and everything set via setValueQDomDocument doc = KDUpdater::UpdateOperation::toXml();// if you need any information to undo the operation you did,// add them to the doc herereturn doc;}bool fromXml( const QDomDocument& doc ){// automatically loads the operation's arguments and everything set via setValueif( !KDUpdater::UpdateOperation::fromXml( doc ) )return false;// if you need any information to undo the operation you did,// read them from the doc herereturn true;}
};

最后,您需要注册您的自定义操作类,如下所示:

#include <UpdateOperationFactory>KDUpdater::UpdateOperationFactory::instance().registerUpdateOperation< CustomOperation >( "CustomOperation" );

现在,您可以在安装程序中使用您的操作了,方式和预定义操作相同。

预定义变量

您可以在脚本中使用以下预定义的变量来方便文件夹访问:

符号 描述
ProductName 要安装的产品的名称,如config.xml中所定义。
ProductVersion 要安装的产品的版本号,如config.xml中所定义。
Title 安装程序的标题,如config.xml中所定义。
Publisher 安装程序的发布者,如config.xml中所定义。
Url 产品网址,如config.xml中定义。
StartMenuDir 开始菜单组,如config.xml中所定义。 仅在Windows上可用。
TargetDir 用户选择的安装目标文件夹。
DesktopDir 包含用户桌面的文件夹名称。仅在Windows上可用。
os 当前平台:"x11", "win", or "mac"。变量已启用:请改用systemInfo。
RootDir 文件系统的根目录。
HomeDir 当前用户的主目录。
ApplicationsDir 应用程序文件夹。
例如,Windows上的C:\Program Files,Linux上的/opt和macOS上的/Applications。
另请参阅表格,列出了Windows上应用程序目录示例。
ApplicationsDirX86 32位程序的应用程序文件夹。 这在Windows上很有用,在其他平台上与ApplicationsDir相同。例如,Windows上的C:\Program Files (x86)。
另请参阅表格,列出了Windows上应用程序目录示例。
ApplicationsDirX64 64位程序的应用程序文件夹。 这在Windows上很有用,在其他平台上与ApplicationsDir相同。例如,Windows上的C:\Program Files。
另请参阅表格,列出了Windows上应用程序目录示例。
InstallerDirPath 包含安装程序可执行文件的目录。
InstallerFilePath 安装程序可执行文件的文件路径。
UserStartMenuProgramsPath 包含当前用户开始菜单中各子项的文件夹的路径。例如,C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs,仅在Windows上可用。
AllUsersStartMenuProgramsPath 包含所有用户开始菜单中各子项的文件夹的路径。例如,C:\ProgramData\Microsoft\Windows\Start Menu\Programs,仅在Windows上可用。

可以通过调用installer::value()来解析变量。 如果嵌入在“ @”中,它们也可以是作为的字符串的一部分,并作为参数传递给安装操作:

if (installer.value("os") === "win") {component.addOperation("CreateShortcut", "@TargetDir@/MyApp.exe", "@StartMenuDir@/MyApp.lnk");
}

例如,Windows上的应用程序目录:

操作系统 (Windows) Qt Installer Framework 变量 示例路径
32bit 32bit ApplicationsDir C:\Program Files
ApplicationsDirX86 C:\Program Files
ApplicationsDirX64 C:\Program Files
64bit 32bit ApplicationsDir C:\Program Files (x86)
ApplicationsDirX86 C:\Program Files (x86)
ApplicationsDirX64 C:\Program Files
64bit ApplicationsDir C:\Program Files
ApplicationsDirX86 C:\Program Files (x86)
ApplicationsDirX64 C:\Program Files

原创造福大家,共享改变世界

献出一片爱心,温暖作者心灵


Qt Installer Framework翻译(7-4)相关推荐

  1. Qt Installer Framework翻译(5-2)

    创建在线安装程序 联机安装程序获取二进制安装文件中的内容以及存储库描述(Updates.xml).请创建一个存储库,并将其上传到Web服务器.然后在用于创建安装程序的config.xml文件中指定存储 ...

  2. Qt Installer Framework实战

    Qt Installer Framework是Qt发布的安装程序支持框架,只需要简单的配置就可以生成安装文件,同时可以通过javascript脚本来定制安装过程. 目录结构 config packag ...

  3. qt linux mac,MacOS下Qt Installer Framework使用教程【个人经验】

    MacOS下Qt Installer Framework怎么使用?使用Qt Installer Framework之前,必须先下载它, 下载地址: 下载完成之后自己进行安装,安装之后,我们就可以开始进 ...

  4. 使用Qt Installer Framework制作软件安装包

    概述 Qt Installer Framework(缩写QIF)是Qt官方用于生成软件安装包的工具.包括Qt Creator和Qt Installer Framework自身的安装包都是由这个工具制作 ...

  5. 《Qt5+安装包制作(Qt Installer Framework)》

    Qt Installer Framework 概述 Qt5可以使用官方的Qt Installer Framework框架制作安装包 Qt Installer Framework框架提供了一组工具和实用 ...

  6. *《Qt5+安装包制作(Qt Installer Framework)》二

    Qt Installer Framework 概述 Qt5可以使用官方的Qt Installer Framework框架制作安装包 The Qt Installer Framework provide ...

  7. Windows程序安装包制作——Qt Installer Framework

    0 前言 Qt提供了制作安装包的工具,本文介绍如何安装和使用. 1 下载 到这里下载QtInstallerFramework-win-x86.exe,即可. 2 安装 双击安装包即可启动安装,保持默认 ...

  8. Qt5+安装包制作(Qt Installer Framework)

    1.下载安装 Qt Installer Framework  1.首先安装Qt Installer Framework,在安装目录里面找到examples里面的yutorial的config和pack ...

  9. Qt Installer Framework应用总结

    Qt Installer Framework应用总结 官网文档位置:https://doc.qt.io/qtinstallerframework/ifw-overview.html 本文主要是讲解配置 ...

最新文章

  1. nodejs操作mysql创建库和表_Nodejs操作MySQL数据库
  2. 对Exchange 事件ID 9154 DSACCESS 返回 DS 通知出现的错误“0x80004005”的处理
  3. CSDN活跃榜 2019-5-22
  4. C++ 高级数据类型(二)—— 字符序列
  5. 理解setState(),异步还是同步?
  6. 更开放的分布式事务 | 蚂蚁金服共建 Seata 社区
  7. 【转】【OPenGL】OPenGL 画图板-- 中点算法画圆
  8. 静态/动态注冊广播的差别
  9. testng_TestNG超时示例
  10. 2018-12-13丛晓强作业
  11. 数据结构折半查找例题_查找-第9章-《数据结构题集》习题解析-严蔚敏吴伟民版...
  12. mate7 android升级包下载,华为mate7 刷机包
  13. 面向对象:寻寻觅觅,诚邀你一起来解开这道迷题
  14. 51nod 1548 欧姆诺姆和糖果【思维+分类讨论】
  15. 降低屏幕亮度,减缓眼疲劳 (linux/windows/firefox/android)
  16. 50070无法访问的问题的排除
  17. exit()和return的含义及区别
  18. kodi remote android,使用Android和iOS在Win10系统中设置Kodi Remote方法
  19. 随笔---有关爬虫的总结
  20. Seneca:NodeJS 微服务框架入门(一)

热门文章

  1. #!/bin/sh与#!/bin/bash的区别
  2. UITableView 系列三 :分类显示和改变外观 (实例)
  3. 深度学习(参数选择)
  4. Linux shell 下的复制和粘贴(Copy Paste Operation on Linux shell)
  5. tensorflow代码中的tf.app.run()
  6. 远程服务器,你不得不知道的命令行操作(一)
  7. 如何用Pygame写游戏(八)
  8. 如何用Pygame写游戏(七)
  9. 《剑指Offer》 跳台阶
  10. Linux拓展通配符的使用