creating desktop shortcut during installation
-
Hi all -
I've been asked to modify my installer to create a desktop shortcut. I've done a little web searching, and the answer seems to lie in creating a javascript (or maybe two). The Qt Installer Framework Manual seems somewhat brief and incomplete, so I have a few questions:
- the docs refer to two kinds of scripts: controller scripting and component scripting. From the examples, it seems that I want to make a component script. Correct?
- also from the examples, the filename should be installscript.qs. Do I have to tell binarycreator to use this .qs? I don't see any hopeful options in the binarycreator help for this.
- I've seen examples use createOperations, and newOperation. Which is appropriate for my use?
- if I call console.log() from within my installscript, should I expect to see its output in the installationlog.txt file?
I'm sure I'll have some more questions, but this will get me started. Thanks...
-
Hi all -
I've been asked to modify my installer to create a desktop shortcut. I've done a little web searching, and the answer seems to lie in creating a javascript (or maybe two). The Qt Installer Framework Manual seems somewhat brief and incomplete, so I have a few questions:
- the docs refer to two kinds of scripts: controller scripting and component scripting. From the examples, it seems that I want to make a component script. Correct?
- also from the examples, the filename should be installscript.qs. Do I have to tell binarycreator to use this .qs? I don't see any hopeful options in the binarycreator help for this.
- I've seen examples use createOperations, and newOperation. Which is appropriate for my use?
- if I call console.log() from within my installscript, should I expect to see its output in the installationlog.txt file?
I'm sure I'll have some more questions, but this will get me started. Thanks...
hi @mzimmers
the InstallerFramework is not widely used, so help will be sparse :(
It is black magic for me too, but I can share my
installerscript.qs
that I use.The script lives in the
meta
folder of the main packages and what it does is offers the user a checkbox to create a desktop iconfunction Component() { // constructor if (!systemInfo.productVersion.startsWith("7")){ component.enabled = true; component.loaded.connect(this, Component.prototype.loaded); }else{ component.enabled = false; } } Component.prototype.createOperations = function() { try { // call the base create operations function component.createOperations(); } catch (e) { console.log(e); } if (systemInfo.productType === "windows") { component.addOperation("CreateShortcut", "@TargetDir@/myApp.exe", "@StartMenuDir@/myApp.lnk", "workingDirectory=@TargetDir@"); component.addOperation("CreateShortcut", "@TargetDir@/myApp.exe", "@HomeDir@/Desktop/myApp.lnk"); } }
inside the package.xml you'll have to add the script via
<Default>script</Default>
<Script>installscript.qs</Script>
I hope this helps!
-
hi @mzimmers
the InstallerFramework is not widely used, so help will be sparse :(
It is black magic for me too, but I can share my
installerscript.qs
that I use.The script lives in the
meta
folder of the main packages and what it does is offers the user a checkbox to create a desktop iconfunction Component() { // constructor if (!systemInfo.productVersion.startsWith("7")){ component.enabled = true; component.loaded.connect(this, Component.prototype.loaded); }else{ component.enabled = false; } } Component.prototype.createOperations = function() { try { // call the base create operations function component.createOperations(); } catch (e) { console.log(e); } if (systemInfo.productType === "windows") { component.addOperation("CreateShortcut", "@TargetDir@/myApp.exe", "@StartMenuDir@/myApp.lnk", "workingDirectory=@TargetDir@"); component.addOperation("CreateShortcut", "@TargetDir@/myApp.exe", "@HomeDir@/Desktop/myApp.lnk"); } }
inside the package.xml you'll have to add the script via
<Default>script</Default>
<Script>installscript.qs</Script>
I hope this helps!
@J-Hilk thanks for replying! This is very helpful. I think the main difference between yours and mine is the location -- I grabbed my script from an example that had it in the installer directory, not the meta sub-directory.
I notice, also that your OS check is:
if (systemInfo.productType === "windows") {
whereas mine is:
if (systemInfo.ProductType == "win") {
which I find odd, but since yours works, I'll go with the winner.
What does this line do?
if (!systemInfo.productVersion.startsWith("7")){
Thanks again...
-
@J-Hilk thanks for replying! This is very helpful. I think the main difference between yours and mine is the location -- I grabbed my script from an example that had it in the installer directory, not the meta sub-directory.
I notice, also that your OS check is:
if (systemInfo.productType === "windows") {
whereas mine is:
if (systemInfo.ProductType == "win") {
which I find odd, but since yours works, I'll go with the winner.
What does this line do?
if (!systemInfo.productVersion.startsWith("7")){
Thanks again...
@mzimmers said in creating desktop shortcut during installation:
if (!systemInfo.productVersion.startsWith("7")){
it checks if it's windows 7 or newer. I only support win 10 so I disable the component in the installer if I detect win7
-
@mzimmers said in creating desktop shortcut during installation:
if (!systemInfo.productVersion.startsWith("7")){
it checks if it's windows 7 or newer. I only support win 10 so I disable the component in the installer if I detect win7
@J-Hilk OK, thanks.
I borrowed from your script, moved mine to meta and rebuilt the installer -- no change. Am I possibly missing something like a binarycreator option to pick up scripts? Here's the line I use to create the installer:
C:\discovery_utility\installer>binarycreator.exe -c config\config.xml -p packages cd_discovery_installer.exe
EDIT: the installscript line was commented out in my package.xml file (no idea why). I removed the commenting, and got this at runtime:
Exception while loading the component script ":\\metadata\com.vendor.product\installscript.qs": Error: Function.prototype.connect: target is not a function on line number: 7
This is line 7:
component.loaded.connect(this, Component.prototype.loaded);
But, this is definitely progress.
-
@J-Hilk OK, thanks.
I borrowed from your script, moved mine to meta and rebuilt the installer -- no change. Am I possibly missing something like a binarycreator option to pick up scripts? Here's the line I use to create the installer:
C:\discovery_utility\installer>binarycreator.exe -c config\config.xml -p packages cd_discovery_installer.exe
EDIT: the installscript line was commented out in my package.xml file (no idea why). I removed the commenting, and got this at runtime:
Exception while loading the component script ":\\metadata\com.vendor.product\installscript.qs": Error: Function.prototype.connect: target is not a function on line number: 7
This is line 7:
component.loaded.connect(this, Component.prototype.loaded);
But, this is definitely progress.
@mzimmers mmh
I don't have more ideas.
Have you checked the short cut example in the docs ?
https://doc.qt.io/qtinstallerframework/qt-installer-framework-startmenu-example.html
-
Well, I got it to create the shortcut (unconditionally, but that's better than nothing). I just commented out that line 7 (above) and it worked.
I do wish someone with more knowledge would augment the docs on the installer, but I can close this out. Thanks for the help.