Qt Installer Framework : Create shortcut on the desktop
-
Hello,
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 -
[SOLVED]
Hey,I am not offering any solution but also seeking for one. As I am facing the same problem, I wondered if you were able to eventually figure out how to make the installer create a desktop shortcut. Any ideas or code that you are willing to share will be greatly appreciated.
Thanks.
-
komates: As far as I can see, the only difference between the code you posted and what works for me on Windows is that you used "createOperationsForPath" where I am using "createOperations". I have no idea if this makes any difference. I am posting a solution that worked fine for me on both Windows and Ubuntu.
The complete code in my installscript.qs looks like:
@function Component()
{
}
Component.prototype.isDefault = function()
{
return true;
}
Component.prototype.createOperations = function()
{
try
{
component.createOperations();
}
catch (e)
{
print(e);
}
if (installer.value("os") === "win")
{
component.addOperation("CreateShortcut", "@TargetDir@/YourApp.exe", "@DesktopDir@/YourApp_name.lnk");
}
if (installer.value("os") === "x11")
{
component.addOperation("CreateDesktopEntry", "/usr/share/applications/YourApp.desktop", "Version=1.0\nType=Application\nTerminal=false\nExec=@TargetDir@/YourApp.sh\nName=YourApp_name\nIcon=@TargetDir@YourApp_icon.png\nName[en_US]=YourApp_name");
component.addElevatedOperation("Copy", "/usr/share/applications/YourApp.desktop", "@HomeDir@/Desktop/YourApp.desktop");
}
}@The first "if" statement is for Windows. It creates a desktop shortcut YourApp_name.lnk for the executable YourApp.exe. Here, YourApp_name is the text that will actually show up under the desktop icon and you may want to make it slightly different from YourApp (e.g., your executable "slimImageViewer.exe" may sit better on the Desktop as "Slim Image Viewer.lnk" than it would as "slimImageViewer.lnk").
The second "if" statement is used on Linux. The first function call creates a .desktop file in the standard location "/usr/share/applications" where it will be visible to the Dash search (I am familiar only with Ubuntu). The third argument is long string that lists the lines of the .desktop file separated by \n, i.e., "line1\nline2\nline3\n...\line10". Some familiarity with the general structure of a .desktop file would be helpful here.
The second function call is create Windows-like experience. It places a copy of that .desktop file on the Desktop so that the user can launch the application by double-clicking a desktop icon.