当前位置:网站首页>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",出现以下界面则添加成功


边栏推荐
- [cloud native | kubernetes] in depth understanding of deployment (VIII)
- SuperMap iClient3D for WebGL 加载TMS瓦片
- 药店管理系统
- 【一天学awk】基础中的基础
- Why should offline stores do new retail?
- Introduction to the pursuit of new subtrate source code - early May: xcm officially launched
- Idea has a new artifact, a set of code to adapt to multiple terminals!
- Biological network analysis using deep learning
- [target tracking] |pytracking configuring win to compile prroi_ pool. pyd
- What is the principle of spectral confocal displacement sensor? Which fields can be applied?
猜你喜欢

Why should offline stores do new retail?

腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?

SuperMap iDesktop 常见倾斜数据处理全流程解析

60 divine vs Code plug-ins!!

Instructions for legend use in SuperMap iclient3d 11i for cesium 3D scene

What is the principle of spectral confocal displacement sensor? Which fields can be applied?

Redis-缓存问题

Hisilicon 3559 developing common sense reserves: a complete explanation of related terms

NoSQL - redis configuration and optimization

A review of quantum neural networks 2022 for generating learning tasks
随机推荐
How to select an OLAP database engine?
Subtrate 源码追新导读-5月上旬: XCM 正式启用
Redis - problèmes de cache
移除无效的括号[用数组模拟栈]
Embedded sig | multi OS hybrid deployment framework
[cf] 803 div2 A. XOR Mixup
Docker安装Mysql8和sqlyong连接报错2058的解决方法[随笔记录]
What are the applications of 3D visual inspection in production flow
AGCO AI frontier promotion (6.30)
Iserver publishing es service query setting maximum return quantity
JMeter之性能测试流程及性能测试关注点
Solve the problem that the server cannot be connected via SSH during reinstallation
Redis-缓存问题
药店管理系统
Set集合
实现多方数据安全共享,解决普惠金融信息不对称难题
SuperMap 3D SDKs_Unity插件开发——连接数据服务进行SQL查询
Building a database model using power designer tools
Hannaiping of Qilin software: the construction of Digital China needs its own open source root community
List集合