Can you addWizardPage on Uninstaller (QtInstallerFramework)?

60 views Asked by At

I am using QtInstallerFramework and I am trying to add custom page when uninstalling the app.

I have custompage.ui file(simple text) and I am adding it in my package.xml:

<UserInterfaces>
        <UserInterface>custompage.ui</UserInterface>
</UserInterfaces>

And this is how I am using it in my componentscript.js:

Component.prototype.componentLoaded = function ()
{
    installer.addWizardPage(component, "CustomPage", QInstaller.ReadyForInstallation)
}

The problem is that the page is displayed only when I install the application. When I uninstall it, CustomPage is not displayed.

Also, with another approach, if I try to add the customized page in my controlscript.js like this:

Controller.prototype.ReadyForInstallationPageCallback = function ()
{
    try {
        installer.addWizardPage(component, "CustomPage", QInstaller.ReadyForInstallation);
    }
    catch (e) {
        QMessageBox.warning("QMessageBox", "", e, QMessageBox.Ok);
    }
}

I am getting this error:

ReferenceError: component is not defined

So, it looks like the component is not loaded at all when the application is uninstalled.
And from Qt documentation we can add custom pages only in components xml file with <UserInterfaces> tag.
Does this mean that we can not use custom gui pages in the uninstaller or I am missing something?

1

There are 1 answers

5
VonC On BEST ANSWER

During installation, package.xml and componentscript.js are in full effect, allowing for dynamic addition of wizard pages.
However, during uninstallation, the framework does not process component scripts in the same manner, which is why you see that custom pages do not appear.

[Installer/Uninstaller Process]
┌────────────────────┐   ┌──────────────────────────┐   ┌─────────────────────────┐
│ package.xml        │   │ componentscript.js       │   │ installscript.qs        │
│  └─ UserInterfaces │──►│  └─ addWizardPage(...)   │──►│  └─ Conditionall        │
└────────────────────┘   └──────────────────────────┘   │    modify wizard        │
            │                              ▲            └─────────────────────────┘
            │                              │                        ▲
            └──────────────────────────────┘                        │
                         Installation Process                       │
                                                            Uninstallation Process

You should use installscript.qs to inject custom logic that runs during both installation and uninstallation (as in this example).
Since this script is executed in both contexts, it is the ideal place to conditionally apply modifications for the uninstallation process.
It can distinguish between installation and uninstallation through conditional checks, enabling specific actions during the uninstallation phase.

Use installer.isUninstaller() to determine if the uninstallation process is underway, and then proceed with custom logic for adding or modifying wizard pages.

You can add custom pages through installer.addWizardPage for the installation process.
For uninstallation, consider modifying existing pages or using available hooks in installscript.qs to interact with the uninstallation process.

In installscript.qs:

function Controller() {
    // Constructor for script
}

Controller.prototype.IntroductionPageCallback = function() {
    if (installer.isUninstaller()) {
        // Custom logic for uninstallation, e.g., modifying the Introduction page
    }
}

so my only option is modifying existing pages(probably with accessing the gui.currentPageWidget()) and adding/removing properties/objects from that page objects.

Yes, something like:

function Controller() {
}

Controller.prototype.IntroductionPageCallback = function() {
    if (installer.isUninstaller()) {
        // Access the current page displayed in the uninstaller wizard
        var currentPage = gui.currentPageWidget();
        
        if (currentPage) {
            // Example modification: Change a label text on the current page
            // Note: That requires knowing the specific object names and structure of the UI
            if (currentPage.findChild("QLabel", "YourLabelObjectName")) {
                currentPage.findChild("QLabel", "YourLabelObjectName").text = "Custom text for the uninstallation process";
            }

            // Example: Adjust visibility of a specific element based on a condition
            var specificCondition = true; // Replace this with your actual condition
            if (specificCondition && currentPage.findChild("QWidget", "YourWidgetObjectName")) {
                currentPage.findChild("QWidget", "YourWidgetObjectName").visible = false;
            }
        }
    }
}