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

4.5k views Asked by At

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

There are 2 answers

2
adam.baker On BEST ANSWER

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>
0
card On

From Qt Installer Framework >= 3.0

You can now use the ApplicationsDir variable, and it'll default to C:\Program Files on Windows, /opt on Linux and /Applications on OS X.

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    ...
    <TargetDir>@ApplicationsDir@/InstallationDirectory</TargetDir>
</Installer>

Reference: http://doc.qt.io/qtinstallerframework/scripting.html#applications-directory-on-windows