9

I use Qt Installer framework 1.5

After the installation, I would like to add a shortcut on the desktop.

In my file installscript.qs, I tried :

Component.prototype.createOperationsForPath = function()
{
  if (installer.value("os") === "win")
  {
    try {
      component.addOperation("CreateShortcut", "@TargetDir@/App.exe", "@DesktopDir@/App.lnk");
    }
    catch (e) {
      print(e);
    }
  }
}

But it doesn't work, the shortcut isn't created and I don't have any error messages. The documentation on Internet is really light.

Any idea ? Thank you

MBach
  • 1,647
  • 16
  • 30
Thomas K
  • 1,067
  • 1
  • 15
  • 35
  • Try adding `component.createOperations();` to the first line of the function. – RA. Feb 22 '14 at 17:04
  • Does it work when you try to create the shortcut on the Start menu? Did you add the script to your package XML file? Did you declare the component (i.e., `function Component() { }`)? – RA. Feb 22 '14 at 18:25
  • No, nothing in the Start menu (I'm on Windows 8.1, so Modern UI is the start menu) Yes I added the script in the XML file – Thomas K Feb 22 '14 at 20:10

2 Answers2

15

Try this. It's working for me.

Component.prototype.createOperations = function()
{
    try {
        // call the base create operations function
        component.createOperations();
        if (installer.value("os") == "win") { 
            try {
                var userProfile = installer.environmentVariable("USERPROFILE");
                installer.setValue("UserProfile", userProfile);
                component.addOperation("CreateShortcut", "@TargetDir@\\MiamPlayer.exe", "@UserProfile@\\Desktop\\MiamPlayer.lnk");
            } catch (e) {
                // Do nothing if key doesn't exist
            }
        }
    } catch (e) {
        print(e);
    }
}
MBach
  • 1,647
  • 16
  • 30
13

I know this answer comes very late, but i hope it can help other users:

(Qt 5.13)

component.addOperation("CreateShortcut", 
                            "@TargetDir@/App.exe",// target
                            "@DesktopDir@/App.lnk",// link-path
                            "workingDirectory=@TargetDir@",// working-dir
                            "iconPath=@TargetDir@/App.exe", "iconId=0",// icon
                            "description=Start App");// description
Max.-F.
  • 303
  • 4
  • 11
  • Do you also know to make it optional, i.e. how to ask user if one is wanted? – user2052153 Oct 11 '22 at 04:30
  • add a QCheckBox widget (with a name) to the page of the installer and at installation check if the widgets checked property has the value true. (I just looked up the code of my old project, I do not know if nowadays there is a better way) – Max.-F. Oct 11 '22 at 18:02