c++qtqt-installer

Setting "Program Files" as a default installation directory in the Qt Installer Framework


In the Qt Installer Framework, all of the demos have TargetDir specification that (for Windows) place the application in, e.g., C:\InstallationDirectory. How can I have it default to Program Files?

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    <Name>Your application</Name>
    <Version>1.2.3</Version>
    <Title>Your application Installer</Title>
    <Publisher>Your vendor</Publisher>
    <StartMenuDir>Super App</StartMenuDir>
    <TargetDir>@RootDir@InstallationDirectory</TargetDir>
</Installer>

Solution

  • There is no option for this, but you can create use the Component Scripting interface to set the installation directory, as described here.

    First, in your packages/com.myorg.myapp/meta/package.xml file, include this reference to the script file.

    <?xml version="1.0" encoding="UTF-8"?>
    <Package>
        ...
        <Script>installscript.qs</Script>
    </Package>
    

    The installscript.qs file, which should be in the same directory as package.xml, should be the following:

    function Component()
    {
         var programFiles = installer.environmentVariable("ProgramFiles");
         if (programFiles != "")
             installer.setValue("TargetDir", programFiles + "/MyPath");
    }
    

    Now the installer framework will suggest C:\Program Files\MyPath or C:\Program Files (x86)\MyPath, as needed.

    Finally, if you want to allow installation paths with spaces (like C:\Program Files\MyPath), you need to enable that specifically in config/config.xml by adding this line:

    <?xml version="1.0" encoding="UTF-8"?>
    <Installer>
         ...
         <AllowSpaceInPath>true</AllowSpaceInPath>
    </Installer>