当前位置:   article > 正文

【Qt IFW】 覆盖安装向导制作_binarycreator 制作卸载

binarycreator 制作卸载

目录

安装Qt IFW

目录结构说明

总体结构

config目录

packages目录

打包安装包

效果图


需求:

给qt编写的桌面软件制作安装向导,检测安装路径,覆盖安装

软件主程序下有OpenVino、python 2个子模块,可选安装

安装Qt IFW

download:Index of /official_releases/qt-installer-framework

Qt Installer Framework Manual:Qt Installer Framework Manual

目录结构说明

总体结构

建立目录结构如下:

  • HyperVisionIFW:项目名称

  • docs:存放文档

  • V0.4.2: 区分不同版本(由D:\Qt\QtIFW-4.2.0\examples\startmenu修改而来)

config目录

config.xml 必要文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Installer>
  3.    <Name>HyperVision</Name>
  4.    <Version>0.4.2</Version>
  5.    <Title>HyperVision安装向导</Title>
  6.    <Publisher>CZTEK</Publisher>
  7.    <!-- Directory name is used in component.xml -->
  8.    <StartMenuDir>HyperVision0.4.2</StartMenuDir>
  9.    <TargetDir>@ApplicationsDirX64@/CZTEK/HyperVision0.4.2</TargetDir>
  10. <WizardStyle>Classic</WizardStyle>
  11.    <StyleSheet>style.qss</StyleSheet>
  12.    <TitleColor>#FFFFFF</TitleColor>
  13. <Logo>logo45.png</Logo>
  14. </Installer>

字段含义见:Configuration File | Qt Installer Framework Manual

style.qss 界面样式表

  1. QWidget
  2. {
  3.    color: white;
  4.    background-color: rgb(65, 65, 65);
  5. }
  6. QPushButton
  7. {
  8.    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(150, 150, 150, 60%), stop:1 rgba(50, 50, 50, 60%));
  9.    border-color: rgb(60, 60, 60);
  10.    border-style: solid;
  11.    border-width: 2px;
  12.    border-radius: 9px;
  13.    min-height: 20px;
  14.    max-height: 20px;
  15.    min-width: 60px;
  16.    max-width: 60px;
  17.    padding-left: 15px;
  18.    padding-right: 15px;
  19. }
  20. QPushButton:pressed, QPushButton:checked
  21. {
  22.    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(50, 50, 50, 60%), stop:1 rgba(150, 150, 150, 60%));
  23. }

packages目录

根据自己项目实际情况划分模块

root.openvino表示为root的子模块

组件名称含义
root主程序
root.openvino深度学习工具库
root.pythonpython解释器

每个组件下包含data、meta 2个文件夹

data下存放需要打包的exe、dll、其他文件

meta下存放安装脚本、UI、组件配置信息

对应界面如下:

root

  • data

./data/script/uninstallscript.qs 卸载脚本,自动点击maintenancetool界面next按钮

  1. // 卸载脚本:如果程序已安装,则会调用 maintenance 工具,自动进行卸载。
  2. function Controller()
  3. {
  4. gui.clickButton(buttons.NextButton);
  5. gui.clickButton(buttons.NextButton);
  6. // 连接信号槽
  7. installer.uninstallationFinished.connect(this, this.uninstallationFinished);
  8. }
  9. // 当卸载完成时,触发
  10. Controller.prototype.uninstallationFinished = function()
  11. {
  12. gui.clickButton(buttons.NextButton);
  13. }
  14. // 与完成页面上的部件交互
  15. Controller.prototype.FinishedPageCallback = function()
  16. {
  17. gui.clickButton(buttons.FinishButton);
  18. }
  • meta

 ./meta/package.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Package>
  3. <DisplayName>HyperVision</DisplayName>
  4. <Description>主程序</Description>
  5. <Version>0.5.2</Version>
  6. <ReleaseDate>2022-02-18</ReleaseDate>
  7. <Default>true</Default>
  8. <Script>installscript.qs</Script>
  9. <UserInterfaces>
  10. <UserInterface>targetwidget.ui</UserInterface>
  11. </UserInterfaces>
  12. </Package>

./meta/installscript.qs 安装脚本,创建快捷方式,覆盖安装

  1. var targetDirectoryPage = null;
  2. // default constructor
  3. function Component()
  4. {
  5. installer.gainAdminRights();
  6. component.loaded.connect(this, this.installerLoaded);
  7. }
  8. // 实用函数,类似于 QString QDir::toNativeSeparators()
  9. var Dir = new function () {
  10. this.toNativeSparator = function (path) {
  11. if (installer.value("os") == "win")
  12. return path.replace(/\//g, '\\');
  13. return path;
  14. }
  15. };
  16. Component.prototype.createOperations = function()
  17. {
  18. try
  19. {
  20. // call default implementation to actually install README.txt!
  21. component.createOperations();
  22. if (systemInfo.productType === "windows")
  23. {
  24. //开始菜单快捷方式
  25. component.addOperation("CreateShortcut",
  26. "@TargetDir@/HyperVision.exe",
  27. "@StartMenuDir@/HyperVision.lnk",
  28. "workingDirectory=@TargetDir@");
  29. //桌面快捷方式
  30. component.addOperation("CreateShortcut",
  31. "@TargetDir@/HyperVision.exe",
  32. "@DesktopDir@/HyperVision.lnk",
  33. "workingDirectory=@TargetDir@");
  34. }
  35. }catch (e) {
  36. print(e);
  37. }
  38. }
  39. // 加载组件后立即调用
  40. Component.prototype.installerLoaded = function()
  41. {
  42. installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);
  43. installer.addWizardPage(component, "TargetWidget", QInstaller.TargetDirectory);
  44. targetDirectoryPage = gui.pageWidgetByObjectName("DynamicTargetWidget");
  45. targetDirectoryPage.windowTitle = "选择安装目录";
  46. targetDirectoryPage.description.setText("请选择程序的安装位置:");
  47. targetDirectoryPage.targetDirectory.textChanged.connect(this, this.targetDirectoryChanged);
  48. targetDirectoryPage.targetDirectory.setText(Dir.toNativeSparator(installer.value("TargetDir")));
  49. targetDirectoryPage.targetChooser.released.connect(this, this.targetChooserClicked);
  50. gui.pageById(QInstaller.ComponentSelection).entered.connect(this, this.componentSelectionPageEntered);
  51. }
  52. // 当点击选择安装位置按钮时调用
  53. Component.prototype.targetChooserClicked = function()
  54. {
  55. var dir = QFileDialog.getExistingDirectory("", targetDirectoryPage.targetDirectory.text);
  56. if (dir != "") {
  57. targetDirectoryPage.targetDirectory.setText(Dir.toNativeSparator(dir));
  58. }
  59. }
  60. // 当安装位置发生改变时调用
  61. Component.prototype.targetDirectoryChanged = function()
  62. {
  63. var dir = targetDirectoryPage.targetDirectory.text;
  64. if (installer.fileExists(dir) && installer.fileExists(dir + "/HyperVision.exe")) {
  65. targetDirectoryPage.warning.setText("<p style=\"color: red\">检测到程序已安装,继续将会被覆盖。</p>");
  66. } else {
  67. targetDirectoryPage.warning.setText("");
  68. }
  69. installer.setValue("TargetDir", dir);
  70. }
  71. // 当进入【选择组件】页面时调用
  72. Component.prototype.componentSelectionPageEntered = function()
  73. {
  74. var dir = installer.value("TargetDir");
  75. if (installer.fileExists(dir) && installer.fileExists(dir + "/maintenancetool.exe")) {
  76. installer.execute(dir + "/maintenancetool.exe", "--script=" + dir + "/script/uninstallscript.qs");
  77. }
  78. }

./meta/targetwidget.ui

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>TargetWidget</class>
  4. <widget class="QWidget" name="TargetWidget">
  5. <property name="geometry">
  6. <rect>
  7. <x>0</x>
  8. <y>0</y>
  9. <width>491</width>
  10. <height>190</height>
  11. </rect>
  12. </property>
  13. <property name="sizePolicy">
  14. <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
  15. <horstretch>0</horstretch>
  16. <verstretch>0</verstretch>
  17. </sizepolicy>
  18. </property>
  19. <property name="minimumSize">
  20. <size>
  21. <width>491</width>
  22. <height>190</height>
  23. </size>
  24. </property>
  25. <property name="windowTitle">
  26. <string>Form</string>
  27. </property>
  28. <layout class="QVBoxLayout" name="verticalLayout">
  29. <item>
  30. <widget class="QLabel" name="description">
  31. <property name="text">
  32. <string>description</string>
  33. </property>
  34. </widget>
  35. </item>
  36. <item>
  37. <layout class="QHBoxLayout" name="horizontalLayout">
  38. <property name="spacing">
  39. <number>6</number>
  40. </property>
  41. <item>
  42. <widget class="QLineEdit" name="targetDirectory">
  43. <property name="readOnly">
  44. <bool>true</bool>
  45. </property>
  46. </widget>
  47. </item>
  48. <item>
  49. <widget class="QPushButton" name="targetChooser">
  50. <property name="text">
  51. <string>...</string>
  52. </property>
  53. </widget>
  54. </item>
  55. </layout>
  56. </item>
  57. <item>
  58. <widget class="QLabel" name="warning">
  59. <property name="enabled">
  60. <bool>true</bool>
  61. </property>
  62. <property name="text">
  63. <string>warning</string>
  64. </property>
  65. </widget>
  66. </item>
  67. <item>
  68. <spacer name="verticalSpacer">
  69. <property name="orientation">
  70. <enum>Qt::Vertical</enum>
  71. </property>
  72. <property name="sizeHint" stdset="0">
  73. <size>
  74. <width>20</width>
  75. <height>122</height>
  76. </size>
  77. </property>
  78. </spacer>
  79. </item>
  80. </layout>
  81. </widget>
  82. <resources/>
  83. <connections/>
  84. </ui>

root.openvino

  • data

  • meta

  • ./meta/package.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Package>
  3. <DisplayName>OpenVino</DisplayName>
  4. <Description>深度学习工具库</Description>
  5. <Version>2021.4.752</Version>
  6. <ReleaseDate>2022-02-18</ReleaseDate>
  7. <Default>true</Default>
  8. </Package>

root.python

  • data

  • meta

./meta/package.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Package>
  3. <DisplayName>Python</DisplayName>
  4. <Description>Python解释器</Description>
  5. <Version>3.7</Version>
  6. <ReleaseDate>2022-02-18</ReleaseDate>
  7. <Default>true</Default>
  8. </Package>

打包安装包

编写一个运行脚本 build.bat

  1. D:/Qt/QtIFW-4.2.0/bin/binarycreator.exe -c ./config/config.xml -p ./packages hypervision-windows-x86-0.4.2.0222.exe -v
  2. pause

-c 指定config路径

-p 指定包路径

双击build.bat

等待运行完毕后,生成hypervision-windows-x86-0.4.2.0222.exe

效果图

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/112694
推荐阅读
相关标签
  

闽ICP备14008679号