• Linux环境下Qt应用程序安装器(installer)制作


    本文介绍Linux环境下Qt应用程序安装器(installer)的制作。

    安装器(installer)是将应用程序安装到操作系统平台的可执行文件,它采用向导式对话框指导用户安装应用程序,如我们在Windows操作系统安装Office软件时,有1个向导让你选择安装哪些组件及安装位置等,最终将程序安装到你的机器上。

    1.软件安装

    安装器的制作需要使用Qt的"binarycreator",需确保程序已经安装,若没安装,可在官网下载安装,地址:Index of /official_releases/qt-installer-framework

    2.创建目录

    创建如下目录:

    "tutorial"目录通常为应用程序名称。这里为了方便,写了个脚本(createdir.sh):

    1. #!/bin/sh
    2. mkdir config
    3. mkdir packages
    4. cd packages
    5. mkdir com.vendor.product
    6. cd com.vendor.product
    7. mkdir data
    8. mkdir meta
    9. echo "done!"

    将脚本拷贝到"tutorial"目录(名称可根据情况改变),赋予可执行权限,并执行,执行完删除。

    1. sudo chmod a+x createdir.sh
    2. ./createdir.sh
    3. rm create.sh

    以项目"fixture"为例,执行完脚本后创建如下目录:

    下面对各目录内容作详细描述。

    3.config目录

    在"config"目录下创建"config.xml"文件,内容如下:

    1. "1.0" encoding="UTF-8"?>
    2. Your application
    3. 1.0.0
    4. Your application Installer
    5. Your vendor
    6. Super App
    7. @HomeDir@/InstallationDirectory

    其中,

    Name:安装程序开始时指示安装程序名称,如下图标记2所示。

    Version:软件程序版本。

    Title:安装器的标题栏显示内容,如下图标记1所示。

    Publish:软件供应商名称。

    StartMenuDir:创建在启动菜单中目录名称。

    TargetDir:应用程序默认安装位置,当然,用户在安装过程中也可以自己选择。

    以上内容可以根据实际情况修改。

    至此,我们完成了“config”文件夹的内容。

    4.data目录

    "data"目录为我们放置打包后的应用程序的地方,Qt应用程序打包方法可参见我以前的博文(Linux环境下Qt应用程序打包与发布-CSDN博客),这里就不详细介绍了。把打包后的所有内容拷贝到这里。

    至此,我们完成了“data”文件夹的内容。

    5.meta目录

    1)安装脚本

    在"meta"目录下创建"installscript.qs"文件,内容如下:

    1. /****************************************************************************
    2. **
    3. ** Copyright (C) 2017 The Qt Company Ltd.
    4. ** Contact: https://www.qt.io/licensing/
    5. **
    6. ** This file is part of the FOO module of the Qt Toolkit.
    7. **
    8. ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
    9. ** Commercial License Usage
    10. ** Licensees holding valid commercial Qt licenses may use this file in
    11. ** accordance with the commercial license agreement provided with the
    12. ** Software or, alternatively, in accordance with the terms contained in
    13. ** a written agreement between you and The Qt Company. For licensing terms
    14. ** and conditions see https://www.qt.io/terms-conditions. For further
    15. ** information use the contact form at https://www.qt.io/contact-us.
    16. **
    17. ** GNU General Public License Usage
    18. ** Alternatively, this file may be used under the terms of the GNU
    19. ** General Public License version 3 as published by the Free Software
    20. ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
    21. ** included in the packaging of this file. Please review the following
    22. ** information to ensure the GNU General Public License requirements will
    23. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
    24. **
    25. ** $QT_END_LICENSE$
    26. **
    27. ****************************************************************************/
    28. function Component()
    29. {
    30. // constructor
    31. component.loaded.connect(this, Component.prototype.loaded);
    32. if (!installer.addWizardPage(component, "Page", QInstaller.TargetDirectory))
    33. console.log("Could not add the dynamic page.");
    34. }
    35. Component.prototype.isDefault = function()
    36. {
    37. // select the component by default
    38. return true;
    39. }
    40. Component.prototype.createOperations = function()
    41. {
    42. try {
    43. // call the base create operations function
    44. component.createOperations();
    45. } catch (e) {
    46. console.log(e);
    47. }
    48. }
    49. Component.prototype.loaded = function ()
    50. {
    51. var page = gui.pageByObjectName("DynamicPage");
    52. if (page != null) {
    53. console.log("Connecting the dynamic page entered signal.");
    54. page.entered.connect(Component.prototype.dynamicPageEntered);
    55. }
    56. }
    57. Component.prototype.dynamicPageEntered = function ()
    58. {
    59. var pageWidget = gui.pageWidgetByObjectName("DynamicPage");
    60. if (pageWidget != null) {
    61. console.log("Setting the widgets label text.")
    62. pageWidget.m_pageLabel.text = "This is a dynamically created page.";
    63. }
    64. }

    这里的内容,可根据实际情况添加或减少。

    2)许可文件

    在"meta"目录下创建"license.txt"文件,内容可自己定义,主要是关于软件安装许可方面的内容。

    3)包描述文件

    在"meta"目录下创建"package.xml"文件,内容如下:

    1. "1.0" encoding="UTF-8"?>
    2. The root component
    3. Install this example.
    4. 0.1.0-1
    5. 2010-09-21
    6. "Beer Public License Agreement" file="license.txt" />
    7. script

    这里,

    DisplayName:软件安装时,由用户选择勾选的组件,如下图1标记1。

    Description:软件安装时,右侧描述,如下图1标记2。

    Version:软件版本。

    ReleaseDate:发布日期。

    Licenses:许可,这里可指示许可文件名称,也就是2)中的"license.txt"文件,内容将显示在向导对话框中,如下图2中标记1。

    Script:安装脚本,也就是1)中的"installscript.qs"文件。

    以上内容可以根据实际情况修改。

    图1

    图2

    至此,我们完成了“meta”文件夹的内容。

    6.制作

    切换到主目录下,也即"tutorial"目录,输入指令:

    1. export PATH=/opt/Qt5.13.2/QtIFW-4.3.0/bin:$PATH
    2. binarycreator -c config/config.xml -p packages YourInstaller

    这里的"QtIFW-4.3.0"目录为你实际安装的版本,路径也类似,"YourInstaller"可自己根据实际情况指定。

    至此,我们完成了程序安装器的制作。

    总结,本文介绍了Linux环境下Qt应用程序安装器(installer)的制作。

  • 相关阅读:
    点云数据集ShapeNet
    网络游戏协议:基于Protobuf的序列化与反序列化
    在CSV文件读取时id读取之后成了‘锘縤d‘,该怎么修改
    云享·人物丨造梦、探梦、筑梦,三位开发者在华为云上的寻梦之旅
    SQL复杂查询-除法实现-做题理解
    RPC通信原理以及项目的技术选型
    mysql索引创建语句记录
    链式-父类中返回子类对象
    管理体系标准
    Do you want them to be removed from the project too?
  • 原文地址:https://blog.csdn.net/propor/article/details/133811342