用Inno Setup打包QT程序输出安装包

InnoSetup打包编译好的QT程序

文章目录

介绍

Inno Setup:用于打包安装程序

具体步骤

  1. 首先打开inno setup compiler
  2. 第二步
  3. 接下来按照图示进行

一路next,会弹出一个编译脚本,然后点击是

  1. 确认脚本无误后,单击运行,输出安装包

自定义脚本

在配置完成后,生成的脚本中,就是以script的形式写出了配置内容,可以自行更改。

一个完整的示例

ini 复制代码
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "qosbrowser"
#define MyAppVersion "0.0.1"
#define MyAppPublisher "XiaoDouLaoShi"
#define MyAppURL "https://www.example.com/"
#define MyAppExeName "qosbrowser.exe"
#define MyEnv "prod"
#define MyRes "static"
#define MyBuild "..\build\build-qos-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\qosbrowser\release"


; 基本信息设置
[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.)
; 它表示一个产品安装包的唯一id,如果做另外一个新产品则需要重新生成一个appid
AppId={{95827DF0-FC44-439C-9225-6CB9BCC43A55}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=.\output
OutputBaseFilename={#MyAppName}_setup_{#MyEnv}_{#MyAppVersion}
SetupIconFile=.\static\images\logo.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
WizardImageFile={#MyRes}\images\setup.bmp
WizardSmallImageFile={#MyRes}\images\setup_small.bmp

; 多语言安装
[Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"

; 本节是可选的。它定义了安装程序在安装期间将执行的所有用户自定义任务。
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

; 指定需要打包的文件
[Files]
Source: "{#MyBuild}\*"; DestDir: "{app}"; Excludes: "*.cpp,*.h,*.obj,*.res"; Flags: recursesubdirs ignoreversion
Source: "{#MyRes}\tools\VC_redist.x64.exe"; DestDir: "{tmp}/tools"; Flags: ignoreversion

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


[registry]
;本段处理程序在注册表中的键值
Root:HKCU;Subkey:Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers;ValueType: string; ValueName:{app}\qosbrowser.exe;ValueData:~ RUNASADMIN;


; 本节是可选的。定义了安装程序在开始菜单和/或其他位置(如桌面)创建的任何快捷方式。
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

; 部分是可选的,它指定在程序成功安装之后,但在安装程序显示最终对话框之前要执行的任意数量的程序。
[Run]
Filename: "{tmp}\tools\VC_redist.x64.exe"; Parameters: /q;
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

更改引入配置文件/动态库路径

这里指定需要打包的文件的路径

ini 复制代码
; Excludes表示打包时排除哪些文件
[Files]
Source: "{#MyBuild}\*"; DestDir: "{app}"; Excludes: "*.cpp,*.h,*.obj,*.res"; Flags: recursesubdirs ignoreversion

申请管理员权限

如果安装在C盘program files下,则需要管理员权限

ini 复制代码
;以下内容是修改程序,使其默认以管理员权限运行
[registry]
;本段处理程序在注册表中的键值
Root:HKCU;Subkey:Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers;ValueType: string; ValueName:{app}\qosbrowser.exe;ValueData:~ RUNASADMIN;

设置安装过程界面的图标和图片

ini 复制代码
; 下面这个static目录要和output(也就是安装包放置目录)同级
#define MyRes "static"
WizardImageFile={#MyRes}\images\setup.bmp
WizardSmallImageFile={#MyRes}\images\setup_small.bmp

C++程序依赖运行库

需要在脚本中添加安装运行库:VC_redist.x64.exe(有些项目依赖这个运行库,但用户电脑可能没有这个库,所以需要在安装软件时同时配置)

1、在Files 小节下添加运行库路径,(后面的{tmp}目录是生成的临时文件夹)

2、不需要在安装过程中弹出提示安装运行库,在[Run]里添加静默安装:Parameters:/q

ini 复制代码
[Files]
Source: "{#MyRes}\tools\VC_redist.x64.exe"; DestDir: "{tmp}/tools"; Flags: ignoreversion

[Run]
Filename: "{tmp}\tools\VC_redist.x64.exe"; Parameters: /q;

参考:

1\] [慕课网课程](https://coding.imooc.com/class/688.html#Anchor)

相关推荐
励志要当大牛的小白菜43 分钟前
ART配对软件使用
开发语言·c++·qt·算法
爱装代码的小瓶子3 小时前
数据结构之队列(C语言)
c语言·开发语言·数据结构
Maybe_ch4 小时前
.NET-键控服务依赖注入
开发语言·c#·.net
超浪的晨4 小时前
Java UDP 通信详解:从基础到实战,彻底掌握无连接网络编程
java·开发语言·后端·学习·个人开发
终焉暴龙王4 小时前
CTFHub web进阶 php Bypass disable_function通关攻略
开发语言·安全·web安全·php
Edingbrugh.南空5 小时前
Aerospike与Redis深度对比:从架构到性能的全方位解析
java·开发语言·spring
CodeCraft Studio6 小时前
借助Aspose.HTML控件,在 Python 中将 HTML 转换为 Markdown
开发语言·python·html·markdown·aspose·html转markdown·asposel.html
QQ_4376643146 小时前
C++11 右值引用 Lambda 表达式
java·开发语言·c++
aramae6 小时前
大话数据结构之<队列>
c语言·开发语言·数据结构·算法
封奚泽优6 小时前
使用Python实现单词记忆软件
开发语言·python·random·qpushbutton·qtwidgets·qtcore·qtgui