Open ReadMe Example | Qt Installer Framework Manual

Qt Installer Framework Manual | Open ReadMe Example

# Open ReadMe Example

Open ReadMe illustrates how to use the `Component()` function to add a check box to the installation finished page and to open the readme file if end users select the check box.

      <?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>

- The `<Default>` element is set to `true` to preselect the component in the installer.
- The `<Script>` element specifies the file name of the JavaScript file that is loaded to perform operations.
- The `<UserInterfaces>` element specifies the file name of the installer page (.ui file) to use.

      <?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>

## Opening Files After Installation

In installscript.qs, we use the `Component()` function to connect to the `installationFinishedPageIsShown` signal when the installation is complete and to the `installationFinished` signal when the end users click Finish (Done on OS X):

      function Component()
      {
          installer.installationFinished.connect(this, Component.prototype.installationFinishedPageIsShown);
          installer.finishButtonClicked.connect(this, Component.prototype.installationFinished);
      }

We call the component::createOperations() function to override the default method for creating operations:

      Component.prototype.createOperations = function()
      {
          component.createOperations();
      }

If the installation is successful, we call the installer::addWizardPageItem() function to replace the last installer page with a custom page that contains the OpenReadMe check box:

      Component.prototype.installationFinishedPageIsShown = function()
      {
          try {
              if (installer.isInstaller() && installer.status == QInstaller.Success) {
                  installer.addWizardPageItem( component, "ReadMeCheckBoxForm", QInstaller.InstallationFinished );
              }
          } catch(e) {
              console.log(e);
          }
      }

We set the `readMeCheckBox` to `checked` by default and use the QDesktopServices::openURL() function to open the readme file:

      Component.prototype.installationFinished = function()
      {
          try {
              if (installer.isInstaller() && installer.status == QInstaller.Success) {
                  var isReadMeCheckBoxChecked = component.userInterface( "ReadMeCheckBoxForm" ).readMeCheckBox.checked;
                  if (isReadMeCheckBoxChecked) {
                      QDesktopServices.openUrl("file:///" + installer.value("TargetDir") + "/README.txt");
                  }
              }
          } catch(e) {
              console.log(e);
          }
      }

Files:

- openreadme/config/config.xml
- 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
- openreadme/openreadme.pro