介绍QT软件的打包方式。两种方式一种是绿色软件,另一种是可安装软件。

QT软件打包

介绍两种打包方式:

  • 绿色软件。即可以直接双击打开的exe执行文件;
  • 安装软件。需要安装,像普通软件一样安装打开。

准备一个可以编译运行通过的QT工程。生成release版本的exe。

提取库文件

Build Qt creator project with release version. By setting:

  • project -> BuildSettings -> edit build settings: choise Release instead of Debug.

  • Then build and run the project to create release version executable file(.exe).

  • Find executable file(.exe) in your path. And copy it to another folder.

  • Open QT cmd:
    QTCmd

    Note: if MinGW is 64 bit, make sure you create release with MinGW 64bit.

  • Input command:(instead demo.exe with name of your .exe)

    1
    windeployqt E:\QtProject\Executable\demo.exe -qmldir D:\Qt\Qt5.12.3\5.12.3\mingw73_64\qml E:\QtProject\Executable
  • You can see library file is added to the path saved your .exe.

After this, copy libgcc_s_dw2-1.dll, libstdc++-6.dll and libwinpthread-1.dll to the path manually. You can find it in the installation path of your QT(such as: D:\Qt\Qt5.8.0\5.8\mingw53_32\bin).

Last step is to pack all file in the path to one exe file.

方法一:Windows绿色软件

Before, make sure you have a qt creator project work successfully.

需要用到Enigma Virtual Box将所需的文件打包成最后的唯一的可执行文件。下载地址

具体操作:

  • 管理员权限打开Enigma virtual Box。
  • Setting,Enter InputFile Name,Enter Output File Name, and Files(Virtual Bpx Files), like this:

404

  • For Files(Virtual Box Files) settings, you can drag all file in the path except the .exe file.
  • Click Run to create MotorDetection_box.exe(Name can be changed to any name you want).
  • Copy MotorDetection_box.exe to any PC without QT software PC. It works well.

windows可安装软件

工具软件:Inno Setup Compiler。可设置密码等信息。

打开界面,根据界面引导,创建.iss文件,或者打开软件提供的example的iss文件,根据需求修改,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "pumpkin-app"
#define MyAppVersion "v0.0.1"
#define MyAppPublisher "Pumpkin Inc"
#define MyAppURL "https://cn.example.com/"
#define MyAppExeName "pumpkin-app.exe"
#define MyAppAssocName MyAppName + " File"
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{1D592000-1D11-4856-9B7F-1E352369000}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
; OutputDir=D:\projects\app\deploy
OutputDir=./
OutputBaseFilename={#MyAppName}_setup-{#MyAppVersion}
Password=abc
Encryption=yes
Compression=lzma
SolidCompression=yes
WizardStyle=modern

; "ArchitecturesAllowed=x64" specifies that Setup cannot run on
; anything but x64.
ArchitecturesAllowed=x64
; "ArchitecturesInstallIn64BitMode=x64" requests that the install be
; done in "64-bit mode" on x64, meaning it should use the native
; 64-bit Program Files directory and the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone

[Files]
Source: "..\build\bin\Release\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\d3dcompiler_47.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\libEGL.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\libGLESV2.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\opencv_world455.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\opengl32sw.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Concurrent.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Core.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Gui.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Multimedia.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5MultimediaQuick.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Network.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Qml.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5QmlModels.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5QmlWorkerScript.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Quick.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5QuickControls2.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5QuickTemplates2.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5QuickTest.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5RemoteObjects.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Svg.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Test.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5Widgets.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\Qt5WinExtras.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\vc_redist.x64.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\build\bin\Release\translations\*"; DestDir: "{app}\translations"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\audio\*"; DestDir: "{app}\audio"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\bearer\*"; DestDir: "{app}\bearer"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\iconengines\*"; DestDir: "{app}\iconengines"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\imageformats\*"; DestDir: "{app}\imageformats"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\languages\*"; DestDir: "{app}\languages"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\mediaservice\*"; DestDir: "{app}\mediaservice"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\platforms\*"; DestDir: "{app}\platforms"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\playlistformats\*"; DestDir: "{app}\playlistformats"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\qmltooling\*"; DestDir: "{app}\qmltooling"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\Qt\*"; DestDir: "{app}\Qt"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\QtGraphicalEffects\*"; DestDir: "{app}\QtGraphicalEffects"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\QtMultimedia\*"; DestDir: "{app}\QtMultimedia"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\QtQml\*"; DestDir: "{app}\QtQml"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\QtQuick\*"; DestDir: "{app}\QtQuick"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\QtQuick.2\*"; DestDir: "{app}\QtQuick.2"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\QtTest\*"; DestDir: "{app}\QtTest"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\QtWinExtras\*"; DestDir: "{app}\QtWinExtras"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\scenegraph\*"; DestDir: "{app}\scenegraph"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "..\build\bin\Release\styles\*"; DestDir: "{app}\styles"; Flags: ignoreversion recursesubdirs createallsubdirs

; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

方法一:使用Inno setup软件打开运行iss文件即可;

方法二: 命令行执行,创建脚本,package.sh,输入,执行

1
2
3
4
5
6
set -e
SCRIPT_DIR="$( cd "$(dirname "$0")" ; pwd -P)"
cd $SCRIPT_DIR

/c/'Program Files (x86)'/'Inno Setup 6'/ISCC.exe app.iss

忽略加载目录的指定文件夹或文件

Excludes属性设置忽略路径,忽略文件夹直接写出文件夹名即可(相对于source的路径),忽略文件可以如”logs/*”。

onlyifdoesntexist当存在是不复制文件,可有用于保留用户配置文件。

1
2
Source: "{#BuildDir}\*"; Excludes: "config,*__pycache__,algo,logs,dumps"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#BuildDir}\config\*"; CopyMode: onlyifdoesntexist; DestDir: "{app}/config"; Flags: ignoreversion recursesubdirs createallsubdirs