赞
踩
Qt Installer Framework(简称QIF)提供了一组工具和实用程序来创建支持桌面Qt平台的安装程序,支持Linux, Microsoft Windows和macOS操作系统。
这里以Visual Studio 的C++项目为例,步骤如下:
sln
文件打开项目;Release
;以下是Qt Installer Framework打包所需的基本目录结构:
AppDir
|--config
| |--config.xml
|--packages
|--module1_dir
| |--data
| | |--files
| |--meta
| |--package.xml
| |--installscript.qs
|--module2_dir
|...
AppDir
是根目录,名称可自定义;config
用于存放打包的全局配置文件;packages
目录是所有模块的父目录,其下的子目录分别对应各个模块;data
目录,用于存放需要打包的文件;meta
目录,用于存放该模块的配置文件。在第一步已生成了应用的可执行文件并找到了其路径,现在可以把其中的YourApp.exe
、YourApp.lib
和YourApp.exp
文件都拷贝到AppDir/packages/module_dir/data
目录下。然后,把应用依赖的其他动态库、配置文件和资源文件等文件按正确的目录结构拷贝到data
目录下
打开命令行,输入以下命令并执行,就可生成Qt环境所需的文件:
windeployqt.exe 你的目录/AppDir/packages/module_dir/data/YourApp.exe
命令执行完后,会在data
目录下看到Qt所需的动态库等文件。
这里以IFW的示例startmenu
为例,config.xml
的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>Start Menu Shortcut Example</Name>
<Version>1.0.0</Version>
<Title>Start Menu Shortcut Example</Title>
<Publisher>Qt-Project</Publisher>
<!-- Directory name is used in component.xml -->
<StartMenuDir>Qt Installer Framework Examples</StartMenuDir>
<TargetDir>@HomeDir@/IfwExamples/startmenu</TargetDir>
</Installer>
<Name>
标签内的是应用名称;<Version>
用于指定版本号;<Title>
是安装程序的标题栏内容;<Publisher>
是发布者的名称;<StartMenuDir>
用于指定应用在开始菜单的目录名;<TargetDir>
是应用的默认安装目录。<?xml version="1.0" encoding="UTF-8"?>
<Package>
<DisplayName>README.txt</DisplayName>
<Description>A README.txt, accessible through a start menu entry.</Description>
<Version>1.0.0-1</Version>
<ReleaseDate>2013-01-01</ReleaseDate>
<Default>true</Default>
<Script>installscript.qs</Script>
</Package>
在安装程序中,有选择组件的页面,其中的内容对应的就是各个模块。
<DisplayName>
指定的就是该模块在页面中显示的名称;
<Description>
是模块的描述信息
<Version>
是模块的版本号
<ReleaseDate>
表示发布日期
<Default>
设置是否默认勾选
<Script>
用于指定控制安装该模块的脚本文件所在路径
installscript.qs
是用于控制模块安装的脚本,其中定义了很多全局变量和函数,这里也以startmenu
的脚本为例:
function Component() { this.createOperations = function() { var programFilesPath = installer.value("ProgramFilesDir"); var shortcutDirPath = installer.value("DesktopDir"); var shortcutPath = shortcutDirPath + "/MyApp.lnk"; component.createOperations(); if (installer.isUninstaller()) { // 不会在卸载操作中创建快捷方式 return; } // 创建快捷方式 var link = installer.guicreateShortcut(shortcutPath, "@TargetName@"); link.description = "@TargetName@"; link.iconPath = programFilesPath + "/MyApp/icon.ico"; link.write(); } } Component.prototype.createOperations = function() { // call default implementation to actually install GDOsgCloudProject.exe! component.createOperations(); if (systemInfo.productType === "windows") { component.addOperation("CreateShortcut", "@TargetDir@/GDOsgCloudProject.exe", "@StartMenuDir@/GDOsgCloudProject.lnk", "workingDirectory=@TargetDir@", "iconPath=%SystemRoot%/system32/SHELL32.dll", "iconId=2", "description=Run GDOsgCloudProject.exe"); } }
其中,function Component()
是组件的构造函数,其中执行了用户定义的一些操作,如:创建快捷方式等。
前面的所有步骤都完成后,就可以执行一下命令打包了。
binarycreator.exe -c config/config.xml -p packages install.exe -v
其中,c
参数是指定config.xml
文件的路径,p
参数用于指定packages
目录的路径,这两个都可以是相对路径;install.exe
是生成的安装包名称,可按自己的需求指定,默认在AppDir
目录下生成;v
参数表示输出日志信息。
IFW默认会同时生成maintenancetool.exe
用于修复和卸载程序。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。