zoukankan      html  css  js  c++  java
  • qt: qt install framework使用问题;

    qt提供了qt install framework用于程序打包,方便、快捷,并且可以对界面和功能进行自定义。

    但是, 如果使用默认的打包配置,不进行安装页面功能自定义的话, 在修改安装路径时,在对程序进行卸载的时候,会将安装路径下的所有文件

    全部删除。 那么,这就会导致一个问题: 如果用户修改了安装路径,没有新建文件夹用来安装,而是直接安装在了D:目录下,在卸载的时候,会将

    D:下的所有文件全部清除掉。很操蛋的操作!

    参考: https://stackoverflow.com/questions/46455360/workaround-for-qt-installer-framework-not-overwriting-existing-installation?r=SearchResults1、

    这里采用自定义界面和功能的方式来解决该问题:

    1、安装路径设置页面

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>TargetWidget</class>
     <widget class="QWidget" name="TargetWidget">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>491</width>
        <height>190</height>
       </rect>
      </property>
      <property name="sizePolicy">
       <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
      <property name="minimumSize">
       <size>
        <width>491</width>
        <height>190</height>
       </size>
      </property>
      <property name="windowTitle">
       <string>Form</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout">
       <item>
        <widget class="QLabel" name="description">
         <property name="text">
          <string/>
         </property>
        </widget>
       </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
          <widget class="QLineEdit" name="targetDirectory">
           <property name="readOnly">
            <bool>true</bool>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QToolButton" name="targetChooser">
           <property name="sizePolicy">
            <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
             <horstretch>0</horstretch>
             <verstretch>0</verstretch>
            </sizepolicy>
           </property>
           <property name="minimumSize">
            <size>
             <width>0</width>
             <height>0</height>
            </size>
           </property>
           <property name="text">
            <string>...</string>
           </property>
          </widget>
         </item>
        </layout>
       </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout_2">
         <property name="topMargin">
          <number>0</number>
         </property>
         <item>
          <widget class="QLabel" name="warning">
           <property name="enabled">
            <bool>true</bool>
           </property>
           <property name="text">
            <string>TextLabel</string>
           </property>
          </widget>
         </item>
         <item>
          <spacer name="horizontalSpacer">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>40</width>
             <height>20</height>
            </size>
           </property>
          </spacer>
         </item>
        </layout>
       </item>
       <item>
        <spacer name="verticalSpacer">
         <property name="orientation">
          <enum>Qt::Vertical</enum>
         </property>
         <property name="sizeHint" stdset="0">
          <size>
           <width>20</width>
           <height>122</height>
          </size>
         </property>
        </spacer>
       </item>
      </layout>
     </widget>
     <resources/>
     <connections/>
    </ui>
    

    2、脚本

    var targetDirectoryPage = null;
    
    function Component() 
    {
        installer.gainAdminRights();
        component.loaded.connect(this, this.installerLoaded);
    }
    
    Component.prototype.createOperations = function() 
    {
        // Add the desktop and start menu shortcuts.
        component.createOperations();
        component.addOperation("CreateShortcut",
                               "@TargetDir@/Atlas4500Tuner.exe",
                               "@DesktopDir@/Atlas4500 Tuner.lnk",
                               "workingDirectory=@TargetDir@");
    
        component.addOperation("CreateShortcut",
                               "@TargetDir@/Atlas4500Tuner.exe",
                               "@StartMenuDir@/Atlas4500 Tuner.lnk",
                               "workingDirectory=@TargetDir@");
    }
    
    Component.prototype.installerLoaded = function()
    {
        installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);
        installer.addWizardPage(component, "TargetWidget", QInstaller.TargetDirectory);
    
        targetDirectoryPage = gui.pageWidgetByObjectName("DynamicTargetWidget");
        targetDirectoryPage.windowTitle = "Choose Installation Directory";
        targetDirectoryPage.description.setText("Please select where the Atlas4500 Tuner will be installed:");
        targetDirectoryPage.targetDirectory.textChanged.connect(this, this.targetDirectoryChanged);
        targetDirectoryPage.targetDirectory.setText(installer.value("TargetDir"));
        targetDirectoryPage.targetChooser.released.connect(this, this.targetChooserClicked);
    
        gui.pageById(QInstaller.ComponentSelection).entered.connect(this, this.componentSelectionPageEntered);
    }
    
    Component.prototype.targetChooserClicked = function()
    {
        var dir = QFileDialog.getExistingDirectory("", targetDirectoryPage.targetDirectory.text);
        targetDirectoryPage.targetDirectory.setText(dir);
    }
    
    Component.prototype.targetDirectoryChanged = function()
    {
        var dir = targetDirectoryPage.targetDirectory.text;
        if (installer.fileExists(dir) && installer.fileExists(dir + "/maintenancetool.exe")) {
            targetDirectoryPage.warning.setText("<p style="color: red">Existing installation detected and will be overwritten.</p>");
        }
        else if (installer.fileExists(dir)) {
            targetDirectoryPage.warning.setText("<p style="color: red">Installing in existing directory. It will be wiped on uninstallation.</p>");
        }
        else {
            targetDirectoryPage.warning.setText("");
        }
        installer.setValue("TargetDir", dir);
    }
    
    Component.prototype.componentSelectionPageEntered = function()
    {
        var dir = installer.value("TargetDir");
        if (installer.fileExists(dir) && installer.fileExists(dir + "/maintenancetool.exe")) {
            installer.execute(dir + "/maintenancetool.exe", "--script=" + dir + "/scripts/auto_uninstall.qs");
        }
    }
    

      3、覆盖安装

    var targetDirectoryPage = null;
    
    function Component() 
    {
        installer.gainAdminRights();
        component.loaded.connect(this, this.installerLoaded);
    }
    
    Component.prototype.createOperations = function() 
    {
        // Add the desktop and start menu shortcuts.
        component.createOperations();
        component.addOperation("CreateShortcut",
                               "@TargetDir@/Atlas4500Tuner.exe",
                               "@DesktopDir@/Atlas4500 Tuner.lnk",
                               "workingDirectory=@TargetDir@");
    
        component.addOperation("CreateShortcut",
                               "@TargetDir@/Atlas4500Tuner.exe",
                               "@StartMenuDir@/Atlas4500 Tuner.lnk",
                               "workingDirectory=@TargetDir@");
    }
    
    Component.prototype.installerLoaded = function()
    {
        installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);
        installer.addWizardPage(component, "TargetWidget", QInstaller.TargetDirectory);
    
        targetDirectoryPage = gui.pageWidgetByObjectName("DynamicTargetWidget");
        targetDirectoryPage.windowTitle = "Choose Installation Directory";
        targetDirectoryPage.description.setText("Please select where the Atlas4500 Tuner will be installed:");
        targetDirectoryPage.targetDirectory.textChanged.connect(this, this.targetDirectoryChanged);
        targetDirectoryPage.targetDirectory.setText(installer.value("TargetDir"));
        targetDirectoryPage.targetChooser.released.connect(this, this.targetChooserClicked);
    
        gui.pageById(QInstaller.ComponentSelection).entered.connect(this, this.componentSelectionPageEntered);
    }
    
    Component.prototype.targetChooserClicked = function()
    {
        var dir = QFileDialog.getExistingDirectory("", targetDirectoryPage.targetDirectory.text);
        targetDirectoryPage.targetDirectory.setText(dir);
    }
    
    Component.prototype.targetDirectoryChanged = function()
    {
        var dir = targetDirectoryPage.targetDirectory.text;
        if (installer.fileExists(dir) && installer.fileExists(dir + "/maintenancetool.exe")) {
            targetDirectoryPage.warning.setText("<p style="color: red">Existing installation detected and will be overwritten.</p>");
        }
        else if (installer.fileExists(dir)) {
            targetDirectoryPage.warning.setText("<p style="color: red">Installing in existing directory. It will be wiped on uninstallation.</p>");
        }
        else {
            targetDirectoryPage.warning.setText("");
        }
        installer.setValue("TargetDir", dir);
    }
    
    Component.prototype.componentSelectionPageEntered = function()
    {
        var dir = installer.value("TargetDir");
        if (installer.fileExists(dir) && installer.fileExists(dir + "/maintenancetool.exe")) {
            installer.execute(dir + "/maintenancetool.exe", "--script=" + dir + "/scripts/auto_uninstall.qs");
        }
    }
    

      4、翻译

    在脚本中的文字,可以通过qsTr函数进行标记;

    利用

    lupdate installscript.qs  targetWidget.ui -ts [语言].ts
    

    生成ts文件,然后使用linguist进行翻译生成qm文件;

  • 相关阅读:
    div+css之清除浮动
    ASP.NET repeater添加序号列的方法
    html中给图片添加热点
    jquery中read与js中onload区别
    从.net转型,聊聊最近一些面试,薪资和想法
    (9)分布式下的爬虫Scrapy应该如何做-关于ajax抓取的处理(一)
    数学之美--关于图论引申出来的爬虫构想
    (8)分布式下的爬虫Scrapy应该如何做-图片下载(源码放送)
    【转】Bloom Filter布隆过滤器的概念和原理
    【转】Python中的GIL、多进程和多线程
  • 原文地址:https://www.cnblogs.com/yinwei-space/p/10120785.html
Copyright © 2011-2022 走看看