Qt Installer Framework:在桌面上创建快捷方式

时间:2014-02-22 15:10:15

标签: qt qt-installer

我使用Qt Installer framework 1.5

安装完成后,我想在桌面上添加一个快捷方式。

在我的文件installscript.qs中,我尝试了:

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

但它不起作用,没有创建快捷方式,我没有任何错误消息。 互联网上的文档非常简单。

有什么想法吗? 谢谢

2 个答案:

答案 0 :(得分:10)

试试这个。它对我有用。

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);
    }
}

答案 1 :(得分:2)

我知道这个答案来得很晚,但是我希望它可以帮助其他用户:

(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