Qt——Windows端打包发布【全面】

打包发布

参考:
QT的程序打包发布(将QT5的工程项目打包成一个可直接运行的exe程序)【讲解:Qt Widgets Application(正常qt/c++项目)与Qt Quick Application(qml项目)两种打包方式】
QT windows 下生成可执行程序【用打包工具 Engima Virtual Box将windeployqt处理后的目录再次处理,生成一个.exe(不需要任何的.dll文件)】
qt打包发布【详细图步骤】
怎样解决Qt编译出的程序运行时缺少libgcc_s_dw2-1.dll 文件的问题?【文章表达的是:通过“配置Qt5.8的bin目录至环境变量”来解决问题,但实际上我的“系统错误”不是“因忘记配置环境变量”导致的!所以对我目前的错误是无效方法。】
找不到libgcc_s_dw2-1.dll, 尝试重新安装该程序以解决问题.【文章表达的是:配置环境变量可以解决(这个对我的不可行,上面已说),但使用另外方法:从网上下载对应dll,其实做了无用功。】
This application failed to start because it could not find or load the Qt platforms plugins【里面的解决方案我并没有尝试,但是告诉我了,该错误是因为没有了platforms目录的qwindows.dll文件!】

声明

Windows端

急着打包发布,请直接看这两个菜单

  • 解决问题 或 打包步骤,用Qt for Desktop窗口进行windeployqt处理
    • 【拷贝整个目录到其他电脑运行成功】
  • 打包后,再简化打包
    • 【拷贝一个简化打包的.exe文件到其他电脑运行成功】

Linux端

若你在Linux端,只要打开终端 输入:qmake–>make clean–>make,编译产生的.exe可以在开发板子上使用,但是,你将编译后的.exe文件移到Windows端,将无法使用【因为Linux识别的.exe可执行文件要用AptURL工具,而Windows端中没有该工具】!!!
解决:
只能将Linux端开发的Qt项目拷贝一份至Windows端,换MinGW编译器(环境配置),然后重复Windows端打包发布步骤!
在这里插入图片描述

为什么要打包发布

Windows端

移植Debug目录下或Release目录下的.exe文件至其他电脑,在没安装Qt的情况下,双击.exe文件,会弹出这样的警告窗口:
在这里插入图片描述
为了解决这个“系统错误”,有两种方法:
【1】:在对应电脑下载Qt
【2】:打包发布

分析:
【1】—> 可行,但,难道每次移植其他电脑都要安装Qt,操作很繁琐、不方便,为什么不能实现“一移植即可运行”???
【2】—> 可行,只需要在移植前,做繁琐操作,若移植至其他电脑,可实现“一移植即可运行”。
在这里插入图片描述
总结:要打包发布.exe文件!!!

手误,用CMD进行windeployqt处理

在这里插入图片描述
还没看清楚步骤,我就急着用管理员身份打开了CMD,用“windeployqt LightUnifTest.exe”【以下是指令的打印结果,请注意,其中出现该异常“Warning: Cannot find GCC installation directory. g++.exe must be in the path.”】

D:\test\LightUnifTest.exe 32 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Skipping plugin qtvirtualkeyboardplugin.dll due to disabled dependencies.
Direct dependencies: Qt5Core Qt5Gui Qt5Widgets
All dependencies   : Qt5Core Qt5Gui Qt5Widgets
To be deployed     : Qt5Core Qt5Gui Qt5Svg Qt5Widgets
Warning: Cannot find GCC installation directory. g++.exe must be in the path.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Updating libGLESV2.dll.
Updating libEGL.dll.
Updating D3Dcompiler_47.dll.
Updating opengl32sw.dll.
Patching Qt5Core.dll...
Creating directory D:/test/iconengines.
Updating qsvgicon.dll.
Creating directory D:/test/imageformats.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjpeg.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory D:/test/platforms.
Updating qwindows.dll.
Creating D:\test\translations...
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_he.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ko.qm...
Creating qt_lv.qm...
Creating qt_pl.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...

在这里插入图片描述
我并没在意打印结果有没有出现errorOrexception,我拷贝test目录,换台电脑双击打开.exe文件,弹出如图所示的“系统错误”提示框:
在这里插入图片描述

解决问题 或 打包步骤,用Qt for Desktop窗口进行windeployqt处理

解决这些问题:
1.Warning: Cannot find GCC installation directory. g++.exe must be in the path.
2.丢失libstdc+±6.dll、libgcc_s_dw2-1.dll、libwinpthread-1.dll的系统错误

Windows端打包发布步骤,如下:
打开Qt,载入LightUnitTest项目(或其他项目),然后按如图所示的那样操作,用Release构建运行项目,然后找“生成的Release目录里的release目录”下的.exe文件,并拷贝,放入D盘下的test文件夹中(随便放入空文件夹中):
在这里插入图片描述
在这里插入图片描述
然后打开Windows的所有程序中的Qt的Qt5.8 for Desktop窗口,先输入“cd /d D:\test”,来到test目录(或对应的目录),再输入“windeployqt LightUnifTest.exe”,用windeployqt工具将.exe要用的Qt的dll文件都拷贝到test目录中,与.exe文件是同级关系(其中,translations目录,不需要的话,可以删除):
在这里插入图片描述
【以下是指令的打印结果,没有出现任何errorOrexception】

D:\test\LightUnifTest.exe 32 bit, releas
Adding Qt5Svg for qsvgicon.dll
Skipping plugin qtvirtualkeyboardplugin.
Direct dependencies: Qt5Core Qt5Gui Qt5W
All dependencies   : Qt5Core Qt5Gui Qt5W
To be deployed     : Qt5Core Qt5Gui Qt5S
Qt5Core.dll is up to date.
Qt5Gui.dll is up to date.
Qt5Svg.dll is up to date.
Qt5Widgets.dll is up to date.
libGLESV2.dll is up to date.
libEGL.dll is up to date.
D3Dcompiler_47.dll is up to date.
opengl32sw.dll is up to date.
Updating libgcc_s_dw2-1.dll.
Updating libstdc++-6.dll.
Updating libwinpthread-1.dll.
Patching Qt5Core.dll...
qsvgicon.dll is up to date.
qgif.dll is up to date.
qicns.dll is up to date.
qico.dll is up to date.
qjpeg.dll is up to date.
qsvg.dll is up to date.
qtga.dll is up to date.
qtiff.dll is up to date.
qwbmp.dll is up to date.
qwebp.dll is up to date.
qwindows.dll is up to date.
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_he.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ko.qm...
Creating qt_lv.qm...
Creating qt_pl.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...

将test目录拷贝,放入另一台电脑中,双击.exe,成功运行!!!【不同的系统不一定都能正常运行,若还出现“提示缺少某些dll”,也许要从网上下载,放入test目录中!一般按照“打包步骤”做,到运行.exe时,是不会出现问题的!】

问题解决的重要步骤就是:不是用CMD程序,而是用Qt自带的Qt for Desktop程序

打包后,再简化打包

下载Enigma Virtual Box,安装后,使用该工具:
在这里插入图片描述
在这里插入图片描述
然后点击Finish按钮,自动弹出Enigma Virtual Box窗口(或者点击EVB(Enigma Virtual Box)图标),导入要打包的.exe文件,再点击Add按钮,选择Add File(s)项,弹出文件管理器,全中所有文件(选到了文件夹也没有关系,程序只显示文件【补:我错了,platforms文件夹很重要,Add完文件后,在这些dll同级处,新建文件夹New Folder,然后取名为platforms,再然后在该文件夹里添加qwindows.dll文件】),点击打开按钮,接着弹出一个Select Folder窗口,选择OK按钮(若已有该目录,则不会弹出elect Folder窗口),然后在程序的Files中显示,再接着,选择Files Options按钮,弹出的窗口要勾选“Compress Files压缩多个文件”,然后选择OK按钮,窗口消失,接着选择程序中的Process按钮,压缩成功,生成了xxx_boxed.exe,接着可以直接选择Close按钮关闭Process窗口,最后,将“LightUnifTest_boxed.exe”拷贝至另一台电脑,运行正常:
在这里插入图片描述
【补:我错了,platforms文件夹很重要,Add完文件后,在这些dll同级处(即%DEFAULT FOLDER%里),新建文件夹New Folder,然后取名为platforms,再然后在该文件夹里添加qwindows.dll文件,否则会遇到错误 This application failed to start because it could not find or load the Qt platform plugin "windows"菜单讲述的问题!!!】
在这里插入图片描述
补-----------若有文件夹,请这么做,否则会遇到错误警告!---------
在这里插入图片描述
补--------------------------------End-----------------------------------
在这里插入图片描述
在这里插入图片描述

又遇错误 This application failed to start because it could not find or load the Qt platform plugin “windows”

这是添加不全面导致的问题:在这里插入图片描述
问题表示:缺少了platforms目录的qwindows.dll文件;
所以,打开Enigma Virtual Box软件,按照打包后,再简化打包菜单讲述的步骤,
Add File(s)添加文件【platforms目录的文件一定要添加,其他三个可以不添加(特别是translations目录,不需要的话,可以删除),但我都添加了!以防万一嘛~】,最后点击Process按钮,生成LightUnifTest_boxed.exe,再次移到其他电脑,运行正常:
在这里插入图片描述
在这里插入图片描述
注:要在%DEFAULT FOLDER%里新建platforms目录,并添加qwindows.dll文件,最后
才!可!以!点击Process按钮!!!
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章