若急着打包发布,请直接看这两个菜单
解决问题 或 打包步骤,用Qt for Desktop窗口进行windeployqt处理 【拷贝整个目录到其他电脑运行成功】 打包后,再简化打包 【拷贝一个简化打包的.exe文件到其他电脑运行成功】若你在Linux端,只要打开终端 输入:qmake–>make clean–>make,编译产生的.exe可以在开发板子上使用,但是,你将编译后的.exe文件移到Windows端,将无法使用【因为Linux识别的.exe可执行文件要用AptURL工具,而Windows端中没有该工具】!!! 解决: 只能将Linux端开发的Qt项目拷贝一份至Windows端,换MinGW编译器(环境配置),然后重复Windows端打包发布步骤!
移植Debug目录下或Release目录下的.exe文件至其他电脑,在没安装Qt的情况下,双击.exe文件,会弹出这样的警告窗口: 为了解决这个“系统错误”,有两种方法: 【1】:在对应电脑下载Qt 【2】:打包发布
分析: 【1】—> 可行,但,难道每次移植其他电脑都要安装Qt,操作很繁琐、不方便,为什么不能实现“一移植即可运行”??? 【2】—> 可行,只需要在移植前,做繁琐操作,若移植至其他电脑,可实现“一移植即可运行”。 总结:要打包发布.exe文件!!!
还没看清楚步骤,我就急着用管理员身份打开了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文件,弹出如图所示的“系统错误”提示框:
解决这些问题: 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同级处(即