7

I am building installers for my app with the Qt Installer Framework (v2.0.1). I'm building my app for both x86 and x64 on Windows, so I'm building an installer for each architecture, with different VC++ Redistributables packaged in each (vcredist_x86.exe and vcredist_x64.exe from MSVC++2013). The QtIFW documentation is frustratingly short on details, but I found that I can add an operation in installscript.qs to run the vcredist installer silently after my files are extracted:

component.addOperation("Execute", "@TargetDir@/vcredist_x64.exe", "/quiet", "/norestart");

But then I have the problem of determining whether my installer is the x86 or x64 version. Is there a way to determine this from the installscript? Perhaps a way to look through the list of files to be extracted? Or is there an easier way to accomplish this seemingly common task of installing the VCRedists?

The documentation just states this:

To install the runtime libraries on the end-user's system, you need to include the appropriate Visual C++ Redistributable Package (VCRedist) executable with your application and ensure that it is executed when the user installs your application.

But it doesn't offer any details on how to "ensure that it is executed".

Brian O'Neill
  • 71
  • 1
  • 2
  • 2

2 Answers2

3

I had a similar problem. You can get the systems architecture using the systeminfo.currentCpuArchitecture . To find out, whether the given architecture is x64, what I did was:

if(systemInfo.currentCpuArchitecture.search("64") < 0) {
    //x86
} else {
    //x64
}

Note: This will return the OS architecture, so a x86 OS on a x64 CPU will be seen as x86.

Edit: Have a look at: https://github.com/Skycoder42/QtIFW-Advanced-Setup . It's a sample project I created that does a lot of additional stuff to improve working with QtIFW, like for example reparing the install path or properly handling offline/online installers.

Felix
  • 6,885
  • 1
  • 29
  • 54
  • I'd like to be able to build installers for both x86 and x64 from one x64 machine, so using the system's architecture doesn't solve the problem, but thank you for the additional info and examples. – Brian O'Neill May 02 '16 at 20:03
  • Why? I will determinte the **target** architecture on runtime, when the user runs the installer, not the on of the build system. You can use this to find out whether the system supports x64 or not. – Felix May 02 '16 at 21:10
  • Well I currently am building two separate installers. The user can choose if they want the 32-bit or 64-bit version. Perhaps they want the 32-bit install even though they have a 64-bit machine. I could include both vcredist_xxx.exe files and use this code to choose the appropriate one, but it then means I am deciding for the user which version they get rather than allowing them to choose. I will probably just rename each vcredist_xxx.exe to vcredist.exe in both packages, so there is no difference to the installer script. – Brian O'Neill May 02 '16 at 23:20
  • Ah, now I understand. In that case I don't think you can archive this using one installer. You will have to decide for one of your two Ideas – Felix May 03 '16 at 12:48
1

Here's the complete function I use to do this in an installscript.qt. 64 bit only. It checks for a build # less than the currently-available build (26706):

Component.prototype.installVCRedist = function()
{
    var registryVC2017x64 = installer.execute("reg", new Array("QUERY", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64", "/v", "Installed"))[0];
    var doInstall = false;
    if (!registryVC2017x64) {
        doInstall = true;
    }
    else
    {
        var bld = installer.execute("reg", new Array("QUERY", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64", "/v", "Bld"))[0];

        var elements = bld.split(" ");

        bld = parseInt(elements[elements.length-1]);
        if (bld < 26706)
        {
            doInstall = true;
        }
    }

    if (doInstall)
    {
        QMessageBox.information("vcRedist.install", "Install VS Redistributables", "The application requires Visual Studio 2017 Redistributables. Please follow the steps to install it now.", QMessageBox.OK);
        var dir = installer.value("TargetDir");
        installer.execute(dir + "/VC_redist.x64.exe", "/norestart", "/passive");
    }
}
woodbot
  • 31
  • 3
  • How to use this function was missing from your post. I got this working by connecting it to the installationFinished signal of the installer: `function Component() { if (systemInfo.productType === "windows") { installer.installationFinished.connect(this, Component.prototype.installVCRedist); } }` – Timothy Scaffidi Mar 14 '19 at 14:59