当前位置:网站首页>Visual Studio配置Qt并通过NSIS实现项目打包
Visual Studio配置Qt并通过NSIS实现项目打包
2022-06-30 12:05:00 【DeepHao】
Visual Studio配置Qt
点击此处前往阿里软件源下载Qt,我这里使用的是Qt5.14.2,下载后双击安装。需要有Qt的账号,如果没有可以取Qt官网申请。依次点击下一步,再Qt组件选择时,建议如下图所示,将MSVC和MinGW都选中,并且32位和64位都安装上

安装使用Visual Studio 2017,注意勾选"使用C++的桌面开发"
Visual Studio 2017配置Qt5.14.2,选择“工具",扩展和更新,搜索Qt并安装

选择Qt VS Tools,选择Qt Versions,
添加Qt的MSVC路径,找到“qmake.exe",点击确认即可,将32位和64位都添加进去,方便使用时随时切换
NSIS安装
前往官网,下载安装

Qt工程打包
windeployqt实现打包
利用visual studio完成一个Qt工程,如下所示,教程在bilibili,选择x64和release
编译完成后会在工程目录下生成"x64/Release/CoinFlip.exe"文件
在桌面新建一个文件夹Coin,命名随意,将上述.exe文件拷贝至其中
打开Qt自带的命令框(不要使用windows自带的cmd)

VCINSTALLDIR
D:\programming\Microsoft Visual Studio\2017\Community\VC
值为Visual Studio的安装路径下的VC
使用NSIS进一步打包
将上述打包的整个Coin文件夹压缩成“.zip”文件,打开NSIS软件。按照如下所示步骤,完成后点击右下角generate,等待完成就行
完成后出现exe文件,双击安装即可
使用NSIS自定义脚本实现进一步打包
clone此仓库,进入到VimeoSetup目录,将上一步的Coin文件夹替换VimeoSetup下的App文件夹并重命名App
打开“NSIS-UI-Plugin”工程
选择Release或Debug,选择x86,Qt VS Tools中版本选择x86
在"属性"中修改"Qt Installation",点击“应用”,“确定”
完成后,右键"生成",完成后在"Win32\Release"下生成"NSIS-UI-Plugin.dll"文件
如果出现报错但是生成了"NSIS-UI-Plugin.dll"文件,就不用担心,这是因为没有添加NSIS环境变量,所以将NSIS添加至环境变量可以解决,其中值是NSIS安装路径
NSIS_DIR
D:\Program Files (x86)\NSIS

另一种解决方法是将生成的"NSIS-UI-Plugin.dll"文件手动拷贝至"D:\Program Files (x86)\NSIS\Plugins\x86-unicode",并重命名为"nsQtPlugin.dll",如果之前采用的Debug模式则重命名为"nsQtPluginD.dll"
但是还是建议添加环境变量,因为后面的步骤仍然需要添加NSIS环境变量
进入"VimeoSetup",编辑"vimeo-template.nsi"文件,各个变量含义如下
我修改如下,我新建了一个图标,依因此我将突图标换成对应的文件名
完成后保存,添加NSIS环境变量(如上所示)。双击"build-setup.bat",如果是Debug模式双击"build-setup [debug].bat",可以打开"bat"文件看到运行的命令
@echo off
python.exe ..\NsisScriptGenerate.py "%~dp0vimeo-template.nsi" "%~dp0App"
"%NSIS_DIR%\makensisw.exe" "%~dp0\vimeo.nsi"
PAUSE
你可能会遇到以下问题,由于原始NsisScriptGenerate.py采用Python2,因此需要做如下修改
print "file total: " + str(g_extract_file_cmd_total) + ", dir total: " + str(g_create_dir_cmd_total)
换
print("file total: " + str(g_extract_file_cmd_total) + ", dir total: " + str(g_create_dir_cmd_total))
print nsis_script_template_path
换
print(nsis_script_template_path)
print g_root_dir
换
print(g_root_dir)
完成后双击"build-setup.bat",若是Debug模式,双击"build-setup [debug].bat"
如果没有反应,需要添加Python环境变量(因为".bat"文件会调用系统cmd,因此会检索系统环境变量下的Python,参见Python环境变量添加),或手动使用Python在当前目录执行
python ../NsisScriptGenerate.py vimeo-template.nsi App
来生成"vimeo.nsi"文件,然后再双击"build-setup.bat",若是Debug模式,双击"build-setup [debug].bat"
完成后得到"CoinFlip-setup.exe"文件
双击打开,会得到以下安装流程



Python环境变量添加
环境变量添加如下:
将Python安装目录添加至环境变量以及Scripts文件夹路径

如果输入Python总是打开微软应用商店,解决如下:
在设置中搜索"应用执行别名",将响应快捷禁用即可,完成后在"cmd"中输入"python",出现以下界面则添加成功


边栏推荐
- 90. (cesium chapter) cesium high level listening events
- QT MSVC installation and commissioning
- Swagger2自动生成APi文档
- 海思3559万能平台搭建:YUV格式简介
- Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit
- MySQL判断执行条件为NULL时,返回0,出错问题解决 Incorrect parameter count in the call to native function ‘ISNULL‘,
- 1020. number of enclaves
- 【一天学awk】正则匹配
- MySQL composite query
- How to detect 3D line spectral confocal sensors in semiconductors
猜你喜欢
随机推荐
60 divine vs Code plug-ins!!
List collection
MATLAB中polarplot函数使用
Charles打断点修改请求数据&响应数据
ES6新特性介绍
List集合
Two batches of pure milk are unqualified? Michael responded that he was conducting a large-scale screening and sampling inspection of products
How difficult is data governance and data innovation?
Instructions for legend use in SuperMap iclient3d 11i for cesium 3D scene
Four Misunderstandings of Internet Marketing
What is the principle of spectral confocal displacement sensor? Which fields can be applied?
海思3559开发常识储备:相关名词全解
Ensemble de cartes
Joplin implements style changes
Tencent two sides: @bean and @component are used on the same class. What happens?
Vscode select multiple words
MySQL中变量的定义和变量的赋值使用
剑指 Offer 05. 替换空格: 把字符串 s 中的每个空格替换成“%20“
使用Power Designer工具构建数据库模型
海思3559万能平台搭建:获取数据帧修改后编码








