Qt Installer Framework系统信息示例

System Information Example

系统信息示例

Using the systemInfo API in a component script to check operating system version and bitness.

​在组件脚本中使用systemInfo API检查操作系统版本和位。

The System Information Example demonstrates how to use the systemInfo API to detect details about the target operating system.

​系统信息示例演示如何使用systemInfo API来检测有关目标操作系统的详细信息。

The example installer consists of three packages: rootroot.i386 and root.x86_64. The root.i386 and root.x86_64 packages are assumed to contain binaries specific to the architecture. The root package contains logic to check for minimum operating system version. It also hides either the root.i386 or root.x86_64 package, based on the operating system architecture.

示例安装程序由三个包组成:root、root.i386和root.x86_64。假设root.i386和root.x86_64包包含特定于该体系结构的二进制文件。根包包含检查最低操作系统版本的逻辑。它还根据操作系统架构隐藏了root.i386或root.x86_64包。

The logic to detect the operating system features is scripted in the root's installscript.qs file.

检测操作系统功能的逻辑在root的installscript.qs文件中编写。

Helper Functions
帮助函数

The installscript.qs file first declares two helper functions: cancelInstaller() and majorVersion().

installscript.qs文件首先声明了两个帮助函数:cancelInstaller()和majorVersion()。

function cancelInstaller(message)
{
    installer.setDefaultPageVisible(QInstaller.Introduction, false);
    installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);
    installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);
    installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false);
    installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false);
    installer.setDefaultPageVisible(QInstaller.PerformInstallation, false);
    installer.setDefaultPageVisible(QInstaller.LicenseCheck, false);

    var abortText = "<font color='red'>" + message +"</font>";
    installer.setValue("FinishedText", abortText);
}

cancelInstaller() sets all except the last installer page to invisible, and shows an error message on the last one. This is a technique also demonstrated in the componenterror and quitinstaller examples.

​cancelInstaller()将除最后一个安装程序页面之外的所有页面设置为不可见,并在最后一个页面上显示错误消息。这也是在componenterror和quitinstaller示例中演示的一种技术。

function majorVersion(str)
{
    return parseInt(str.split(".", 1));
}

majorVersion() takes a string of the format <number>.<number>.<number>.[...]. It uses the built-in JavaScript functions string.split() and parseInt() to return the first <number> as an integer.

majorVersion()接受<number>格式的字符串 <number>.<number>.<number>.[...] 它使用内置的JavaScript函数string.split()和parseInt()将第一个<number>作为整数返回。

Checking the Operating System Type
检查操作系统类型

The actual checks are executed as soon as the package is loaded, in the Component constructor function.

实际检查在加载包后立即在Component构造函数中执行。

function Component()
{

The function uses the built-in systemInfo.kernelTypesystemInfo.kernelVersionsystemInfo::productType, and systemInfo.productVersion properties to check the minimum system requirements.

​该函数使用内置的systemInfo.kernelType、systemInfo.kernelVersion、systemInfo::productType和systemInfo.productVersion属性来检查最低系统要求。

    var validOs = false;

    if (systemInfo.kernelType === "winnt") {
        if (majorVersion(systemInfo.kernelVersion) >= 6)
            validOs = true;
    } else if (systemInfo.kernelType === "darwin") {
        if (majorVersion(systemInfo.kernelVersion) >= 11)
            validOs = true;
    } else {
        if (systemInfo.productType !== "opensuse"
                || systemInfo.productVersion !== "13.2") {
            QMessageBox["warning"]("os.warning", "Installer",
                                   "Note that the binaries are only tested on OpenSUSE 13.2.",
                                   QMessageBox.Ok);
        }
        validOs = true;
    }

The script uses systemInfo.productType to differentiate between Windows, macOS, and individual Linux distributions.

​该脚本使用systemInfo.productType来区分Windows、macOS和单个Linux发行版。

For macOS and Windows, the script checks the operating system kernel version. For a mapping of kernel to operating system versions, see Darwin and Windows NT.

​对于macOS和Windows,该脚本检查操作系统内核版本。有关内核到操作系统版本的映射,请参阅Darwin和Windows NT。

In the case of Linux, it checks the distribution name and version. If it does not match the specific distribution and version the binaries are presumably built for, the installer shows a warning in a modal dialog, but allows installation.

对于Linux,它会检查发行版名称和版本。如果它与二进制文件可能构建的特定发行版和版本不匹配,安装程序将在模式对话框中显示警告,但允许安装。

If the Windows or macOS version is too old, though, the script calls the cancelInstaller() helper function to prevent an actual installation:

但是,如果Windows或macOS版本太旧,脚本会调用cancelInstaller()辅助函数来阻止实际安装:

    if (!validOs) {
        cancelInstaller("Installation on " + systemInfo.prettyProductName + " is not supported");
        return;
    }
Checking the Operating System Architecture
检查操作系统架构

The next section demonstrates the use of systemInfo.currentCpuArchitecture to choose the appropriate sub-package for a particular architecture:

​下一节将演示如何使用systemInfo.currentPuArchitecture为特定体系结构选择合适的子包:

    installer.componentByName("root.i386").setValue("Virtual", "true");
    installer.componentByName("root.x86_64").setValue("Virtual", "true");

    if ( systemInfo.currentCpuArchitecture === "i386") {
        installer.componentByName("root.i386").setValue("Virtual", "false");
        installer.componentByName("root.i386").setValue("Default", "true");
    }
    if ( systemInfo.currentCpuArchitecture === "x86_64") {
        installer.componentByName("root.x86_64").setValue("Virtual", "false");
        installer.componentByName("root.x86_64").setValue("Default", "true");
    }
}

Depending on the operating system architecture, either the package root.i386 or root.x86_64 is marked Virtual, hiding it from the user. For the package that matches the local architecture, the Default property is set to check the package by default.

根据操作系统体系结构,root.i386或root.x86_64包被标记为Virtual,对用户隐藏。对于与本地体系结构匹配的包,默认情况下将Default属性设置为检查包。

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 -p packages installer.exe
    
  • On Linux or macOS:
    ../../bin/binarycreator -c config/config.xml -p packages installer
    

This creates the installer to the current directory.

这将创建当前目录的安装程序。

Files:

© 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.

### 回答1: Qt Installer Framework 是一个用于创建跨平台安装程序的工具。它是由 Qt 公司开发的,可用于构建 Windows、macOS 和 Linux 上的安装程序。Qt Installer Framework 允许开发者创建自定义的安装界面,支持包括自动更新和卸载在内的高级功能,使得应用程序的安装和升级变得更加方便。此外,Qt Installer Framework 还提供了强大的脚本语言和插件系统,以便开发者可以轻松地添加自己的定制功能。 ### 回答2: Qt Installer Framework是一个开源的安装包框架,用于创建跨平台的安装程序。它是由Qt官方社区开发的,用于帮助开发人员轻松地制作各种类型的安装程序。 Qt Installer Framework具有很多强大的特性。首先,它支持主流操作系统,包括Windows、macOS和Linux。这使得开发人员可以使用相同的框架来创建针对不同平台的安装程序,极大地简化了开发和维护的工作。 其次,Qt Installer Framework提供了一个灵活的界面,开发人员可以轻松地定制安装程序的界面。他们可以选择添加自定义的图标、背景图像和品牌标志等来打造与自己应用程序一致的安装体验。 此外,Qt Installer Framework还支持自定义安装组件,开发人员可以将安装的内容分组到不同的组件中,根据用户需求进行选择性安装。这对于大型应用程序来说非常有用,因为用户可以根据自己的需求选择安装哪些组件,从而减少不必要的空间占用。 另一个重要的特性是Qt Installer Framework支持安装程序的自动升级。开发人员可以配置安装程序,使其能够检测并下载更新,并在用户同意的情况下自动升级程序。这可以确保用户始终使用最新版本的应用程序,提供更好的用户体验以及安全性。 综上所述,Qt Installer Framework是一个功能强大且易于使用的安装包框架,可以帮助开发人员轻松创建跨平台的安装程序。它的灵活性和可定制性使得开发人员可以根据自己的需求创建出符合用户期望的安装体验。 ### 回答3: Qt Installer Framework(简称QtIFW)是一个创建安装程序的开源工具集,用于在Windows、Mac和Linux等操作系统上安装Qt应用程序。 Qt Installer Framework提供了一个易于使用的图形界面,允许开发者自定义安装向导和界面。它支持各种高级功能,如自动更新和升级、安装前检查依赖项、注册表设置、缓存管理等。 Qt Installer Framework的核心概念是组件。开发者可以将应用程序划分为多个组件,并在安装时选择安装哪些组件。这样,用户可以自定义安装过程,只选择需要的功能和资源,减少安装空间和时间。 Qt Installer Framework还支持多语言安装,用户可以选择在安装过程中使用哪种语言,提供了灵活的国际化功能。 此外,Qt Installer Framework还支持数字签名验证和认证,确保安装程序的完整性和可信性。 对于开发者来说,Qt Installer Framework提供了灵活的定制选项,可以自定义安装界面和过程,满足特定需求。开发者可以通过简单的脚本语言,定义安装程序的行为。 总的来说,Qt Installer Framework是一个功能强大、易于使用的工具集,为开发者提供了创建跨平台安装程序的便利,提升了用户体验和应用程序的可用性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值