1. 程式人生 > >qt 安裝包生成2

qt 安裝包生成2

其他 版權 流程 tag lan include %s force detail

使用Qt Installer Framework制作安裝包

2018年07月01日 03:45:37 大黃老鼠 閱讀數:878 標簽: qt 個人分類: Qt 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/qq_32768743/article/details/80871697

步驟

制作安裝包的步驟:

  • 去官網下載Qt Installer Framework的安裝包並安裝(已經安裝的請跳過這步)
  • 使用windeployqt.exe集齊所需依賴
  • 使用binarycreator.exe創建安裝包

具體操作流程:

安裝Qt Installer Framework

下載地址:http://download.qt.io/official_releases/qt-installer-framework/

技術分享圖片
技術分享圖片
技術分享圖片
技術分享圖片

搜集依賴

  • 使用Release模式構建項目
    技術分享圖片
    技術分享圖片
  • 在release目錄下刪掉不必要的文件
    技術分享圖片
  • 運行windeployqt.exe命令
[windeployqt.exe路徑] --release --qml --qmldir [qml源碼路徑] [exe文件路徑]
  • 1

技術分享圖片

如在我的環境下是

D:\Qt\Qt5.11.0\5.11.0\mingw53_32\bin\windeployqt.exe --release --qml --qmldir D:\src\qml\huorong\ huorong.exe
  • 1
  • 手動拷貝其他的dll

我使用的是mingw53_32,需要拷貝以下文件

libgcc_s_dw2-1.dll libstdc++-6.dll libwinpthread-1.dll

技術分享圖片

創建安裝包

  • 將上面搜集的依賴拷貝到installer\packages\cn.net.pikachu.huorong\data文件夾下
    技術分享圖片
  • 運行binarycreator.exe命令
[binarycreator.exe路徑] -c [config.xml路徑] -p [packages路徑] [生成的安裝程序exe文件名] -v
  • 1

技術分享圖片

如在我的環境下是

D:\Qt\QtIFW-3.0.4\bin\binarycreator.exe -c installer/config/config.xml -p installer/packages huorong_install.exe -v
  • 1

最後的演示效果

技術分享圖片

思考與總結

如果Qt提供一鍵生成安裝包就好了,何必這麽麻煩呢?應該可以把這些操作用腳本寫好,然後集成到QtCreator中。

附:

配置文件

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<Installer>
    <Name>火絨安全軟件</Name>
    <Version>0.1.0</Version>
    <Title>火絨安全軟件</Title>
    <Publisher>大黃老鼠</Publisher>
    <!-- Directory name is used in component.xml -->
    <StartMenuDir>pikachu</StartMenuDir>
    <TargetDir>@HomeDir@/pikachu/huorong</TargetDir>
</Installer>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package>
    <DisplayName>火絨安全軟件</DisplayName>
    <Description>可執行文件</Description>
    <Version>0.1.0-1</Version>
    <ReleaseDate>2018-07-01</ReleaseDate>
    <Default>true</Default>
    <Script>installscript.qs</Script>
    <ForcedInstallation>true</ForcedInstallation>
</Package>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

installscript.qs

/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the FOO module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

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@/huorong.exe", "@StartMenuDir@/火絨安全軟件.lnk",
            "workingDirectory=@TargetDir@", "iconPath=%SystemRoot%/system32/SHELL32.dll",
            "iconId=2", "description=Open README file");
        component.addOperation("CreateShortcut", "@TargetDir@/huorong.exe", "@HomeDir@/Desktop/火絨安全軟件.lnk");

        component.addOperation("CreateShortcut", "@TargetDir@/maintenancetool.exe", "@StartMenuDir@/更新或卸載 火絨安全軟件.lnk");
    }

qt 安裝包生成2