Quit Installer Example

Quit Installer illustrates how to use the Component() function to display a message box to end users for quitting the installation if some requirements for the installation are not met.
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>Quit Installer Example</Name>
<Version>1.0.0</Version>
<Title>Quit Installer Example</Title>
<Publisher>Qt-Project</Publisher>
<StartMenuDir>Qt IFW Examples</StartMenuDir>
<TargetDir>@HomeDir@/IfwExamples/quitinstaller</TargetDir>
</Installer>
- The
<Default>element is set totrueto preselect the component in the installer. - The
<Script>element specifies the file name of the JavaScript file that is loaded to perform operations.
<?xml version="1.0"?>
<Package>
<DisplayName>Quit an installer</DisplayName>
<Description>Quits the installer in a nice way, if there is something missing</Description>
<Version>1.0.1</Version>
<ReleaseDate>2013-02-27</ReleaseDate>
<Default>true</Default>
<Script>installscript.js</Script>
</Package>
Quitting the Installation
In installscript.js, we use the Component() function to display a message box for quitting the installer to end users:
function Component() { var result = QMessageBox["question"]("test.quit", "Installer", "Do you want to quit the installer?<br>" + "This message box was created using JavaScript.", QMessageBox.Ok | QMessageBox.Cancel);
If end users select OK, we use the installer::setValue() function to display a message and the installer.setDefaultPageVisible() function to hide the subsequent installer pages:
if (result == QMessageBox.Ok) {
installer.setValue("FinishedText", "<font color='red' size=3>The installer was quit.</font>");
installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);
installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false);
installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);
installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false);
installer.setDefaultPageVisible(QInstaller.PerformInstallation, false);
installer.setDefaultPageVisible(QInstaller.LicenseCheck, false);
gui.clickButton(buttons.NextButton);
If end users select Cancel, we display the default installer pages and use the installer::setValue() function to display another message on the last installer page:
} else {
installer.setValue("FinishedText",
"<font color='green' size=3>The installer was not quit by JavaScript.</font>");
}
}
Files: