使用 QtIFW-1.5.0,到目前为止,我已经能够在 Windows 上为我的 Qt 应用程序生成一个在线安装程序。安装程序从我的 Web 服务器下载相应的软件包,并执行控制脚本 installscript.qs 中定义的一些操作,例如将一些键写入注册表并创建带有图标的桌面快捷方式:
installscript.qs:
Component.prototype.createOperations = function()
{
try
{
// call the base create operations function
component.createOperations();
// Add some keys to registry;
var userProfile = installer.environmentVariable("USERPROFILE");
installer.setValue("UserProfile", userProfile);
var reg = installer.environmentVariable("SystemRoot") + "\System32\reg.exe";
var key= "HKCU\Software\Company\Product";
component.addOperation("Execute", reg, "ADD", key, "/f");
component.addOperation("Execute", reg, "ADD", key, "/v", "productId", "/t", "REG_BINARY");
// Add a desktop shortcut with icon:
component.addOperation("CreateShortcut",
"@TargetDir@\MyExecutable.exe",
"@UserProfile@\Desktop\MyExecutable.lnk",
"workingDirectory=@TargetDir@",
"iconPath=@TargetDir@\MyIcon.ico");
}
catch (e)
{
print(e);
}
}
好的,但是我需要写入注册表的另一个键是软件包版本号,在安装程序配置文件配置中定义.xml在标记中
<Version></Version>
如何从 installscript.qs 获取此值?我读了--我说了更多:研究了--文档组件QML类型和安装程序QML类型,我没有找到任何对版本的引用,除了:
安装程序 QML 类型:
boolean versionMatches(string version, string requirement)
这对我来说没用,因为你必须知道版本,这正是我发现的。
因此,任何帮助将不胜感激。
调用
var version = installer.value("ProductVersion");
以获取config.xml
文件中指定的版本。