Qt官方的安装包制作框架 Qt installer framework

以前打包都用第三方的NSIS,很简单也很方便。无意了解到Qt Installer Framework,是Qt官方的安装包制作框架。所以还是了解学习一下官方的打包安装方法吧。


在网上看到Qt Installer Framework, Qt默认包的发布框架。
现在从零开始记录下Qt Installer Framework的安装使用方法:
下载地址:http://download.qt.io/official_releases/qt-installer-framework/2.0.3/
里面各个平台的都有下载,我这里有windows下用的 QtInstallerFramework-win-x86.exe
然后安装。我安装到D:\Qt\QtIFW2.0.3

在D:\Qt\QtIFW2.0.3\examples下有很多例子。现在我们仿照例子来做一个自己的程序打包的工程:

1.将examples下找一个工程,复制一份,重新命个名,复制的目的是为了参照例子(startmenu)中的目录结构, 现在目录结构如下,然后在org.qtproject.ifw.example下创建了一个data目录,这个目录就是用来存放你要打包的所有库和应用程序等文件。目录结构如下:

Qt官方的安装包制作框架 Qt installer framework_第1张图片

2.将创建的这个文件夹myQIFW 复制到D:\Qt\QtIFW2.0.3\bin下,复制到这的目的只是为了方便用bin下面的工具binarycreator.exe,其实如果你将D:\Qt\QtIFW2.0.3\bin加入环境变量,在任何地方都可以用这个命令。不扯那么多了,命令如下:

./binarycreator.exe -c myQIFW/config/config.xml -p myQIFW/packages my_install.exe -v

其实这样便生成了一个安装包my_install.exe


现在我们试着运行一下,由于是例子里复制过来的,除了目录名,其它没经过任何修改,所以安装步骤里的名字,目录,说明等都不是我们想要的。经过这一步试验,你能更好的理解工程目录下的config.xml ,以及meta下的文件分别代表什么意思。
现在回过头来看一下config.xml
这里有一份官方的说明文档 http://doc.qt.io/qtinstallerframework/ifw-globalconfig.html


<Installer>
    <Name>PSSTCName>
    <Version>1.0.0Version>
    <Title>安装向导Title>
    <Publisher>Qt-ProjectPublisher>
    
    <StartMenuDir>PSSTC安保协会StartMenuDir>
    
    <TargetDir>@RootDir@/PSSTCTargetDir>
Installer>

Qt installer framework引入了组件的概念;
若想该组件包必须安装时,可在packages.xml文件中添加ForcedInstallation:


<Package>
    <DisplayName>主程序DisplayName>
    <Description>.Description>
    <Version>1.0.0-1Version>
    <ReleaseDate>2013-01-01ReleaseDate>
    <Default>trueDefault>
    <Script>installscript.qsScript>
    <ForcedInstallation>trueForcedInstallation>
Package>

若该属性设置为false或者为设置,那么该组件就是可选安装的.

创建开始菜单中的快捷方式;创建桌面快捷方式,修改installscript.qs:

function Component()
{
    // default constructor
}

Component.prototype.createOperations = function()
{
    // call default implementation to actually install README.txt!
    component.createOperations();

    if (systemInfo.productType === "windows") {
        component.addOperation("CreateShortcut", "@TargetDir@/PSSTC.exe", "@StartMenuDir@/PSSTC.lnk");
        component.addOperation("CreateShortcut", "@TargetDir@/PSSTC.exe", "@HomeDir@/Desktop/PSSTC.lnk");

        component.addOperation("CreateShortcut", "@TargetDir@/maintenancetool.exe", "@StartMenuDir@/更新或卸载.lnk");
    }
}

其它说明:生成安装文件

离线安装:

  binarycreator --offline-only -c installer-config/config.xml -p packages-directory -t installerbase SDKInstaller

在线安装:

  binarycreator -c installer-config/config.xml -p packages-directory -e com.nokia.sdk.qt,com.nokia.qtcreator -t installerbase SDKInstaller

你可能感兴趣的:(QT,C++,工具)