作者:翟天保Steven
版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处
开发制作流程
1)查看Qt项目所在文件夹,其中64_release是用到的64位release版本的第三方库。

2)生成的build文件在上级目录。

3)创建一个windeployqt.txt文件,将txt改为bat。

4) 右键编辑,输入如下命令,该命令的意思是在系统根目录的Desktop也就是桌面,创建一个名为Test的文件夹。
@echo off
md %USERPROFILE%\Desktop\Test
5) 使用copy命令,复制项目上级目录中的build文件夹中的exe可执行文件,至Test文件夹;使用xcopy命令把第三方库的所有文件拷贝到Test。注意..\是上级目录,.\是当前目录。
copy ..\build-ImageProcessZTB-Desktop_Qt_5_12_9_MSVC2017_64bit-Release\ImageProcessZTB.exe %USERPROFILE%\Desktop\Test
xcopy .\64_release\ %USERPROFILE%\Desktop\Test\ /s /e /c /y /h /r
6)使用cd /d命令,使cmd指向Test文件夹,用windeployqt命令即可自动打包exe文件,如果qt项目使用的是qt widget,则 windeployqt就够了;如果用的是qml,则后面还要加上--qmldir,并附带你电脑上Qt安装目录的qml文件夹路径。
cd /d %USERPROFILE%\Desktop\Test
windeployqt ImageProcessZTB.exe --qmldir D:\Qt\5.12.9\msvc2017_64\qml
7)如下图所示,是cmd打包过程。

8)至此,打包工作完毕,Test文件夹中双击exe即可执行程序,更换电脑也没问题,当然有的电脑还可能需要配置window库才能打开。

9) 软件界面如下图所示。

完整命令
@echo off
md %USERPROFILE%\Desktop\Test
copy ..\build-ImageProcessZTB-Desktop_Qt_5_12_9_MSVC2017_64bit-Release\ImageProcessZTB.exe %USERPROFILE%\Desktop\Test
xcopy .\64_release\ %USERPROFILE%\Desktop\Test\ /s /e /c /y /h /r
cd /d %USERPROFILE%\Desktop\Test
windeployqt ImageProcessZTB.exe --qmldir D:\Qt\5.12.9\msvc2017_64\qml
图示

如果文章帮助到你了,可以点个赞让我知道,我会很快乐~加油!