System Information Example

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

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

The example installer consists of three packages: root, root.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.

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

Helper Functions

The installscript.qs file first declares two helper functions: cancelInstaller() and 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.

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.

Checking the Operating System Type

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

function Component()

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

    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.",
        validOs = true;

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

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.

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.

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

    if (!validOs) {
        cancelInstaller("Installation on " + systemInfo.prettyProductName + " is not supported");

Checking the Operating System Architecture

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

    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.

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

The installer is created in the current directory.


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