Qt windeployqt打包分析

Qt程序打包一般流程:

开始菜单 - 打开Qt对应编译器命令行 - 输入windeployqt test.exe命令

那么,这个过程经历了什么呢?这个就是今天要分析的主题。

前置知识 - cmd命令

echo

回显

@echo off  #从本行开始关闭回显。一般批处理第一行都是这个

cd

切换目录

cd /D D:\Qt\ #可以同时更改盘符和目录 /d 和/D不区分大小写

set

设置变量。引用变量可在变量名前后加 % ,即 %变量名%

set #直接输入set可显示目前所有可用的变量,包括系统变量和自定义的变量
echo %SystemDrive% #显示系统盘盘符。系统变量可以直接引用
set p=123 #设置变量p,并赋值为123
echo %p%  #显示变量p的值

打开Qt命令行分析

开始菜单-Qt命令行-右键打开文件对应位置
在这里插入图片描述
然后再右键查看属性,可以看到目标这里
在这里插入图片描述

代码如下:

C:\Windows\System32\cmd.exe /A /Q /K D:\Qt\5.15.2\mingw81_64\bin\qtenv2.bat
  • /K

    运行命令,然后在CMD提示符下保持打开状态。

    这对于测试很有用,例如检查变量。

  • /A

    输出 ANSI 字符。

  • /Q

    关闭echo

即,调用cmd命令行,设置终端窗口不关闭,输出ANSI字符,关闭echo输出属性,然后运行qtenv2.abt脚本。

qtenv2.bat

这里分析一些,运行的这个脚本是干什么的。qtenv2.bat分为两个版本,略有区别。

MSVC

@echo off
echo Setting up environment for Qt usage...
set PATH=D:\Qt\5.15.2\msvc2019_64\bin;%PATH%
cd /D D:\Qt\5.15.2\msvc2019_64
echo Remember to call vcvarsall.bat to complete environment setup!

MinGW

@echo off
echo Setting up environment for Qt usage...
set PATH=D:\Qt\5.15.2\mingw81_64\bin;D:/Qt/Tools/mingw810_64\bin;%PATH%
cd /D D:\Qt\5.15.2\mingw81_64
  1. 显示 Setting up environment for Qt usage...文本
echo Setting up environment for Qt usage...
  1. 这段其实不好理解。写了一个demo.bat理解了。
set PATH=D:\Qt\5.15.2\mingw81_64\bin;D:/Qt/Tools/mingw810_64\bin;%PATH%

我们可以先看demo.bat

set a=D:/a
set a=E:/b;%a%
pause

先设置了一个变量a,然后再对这个变量a进行赋值,但注意,这里后面;%a%是什么意思呢?我们先看运行结果:

D:\Code>demo.bat

D:\Code>set a=D:/a

D:\Code>set a=E:/b;D:/a

D:\Code>pause
请按任意键继续. . .

也就是说,这里set a=E:/b;%a%的意思应该是追加赋值,即原本a=D:/a,现在再追加一个值,变为

a=E:/b;D:/a

那么set PATH=D:\Qt\5.15.2\mingw81_64\bin;D:/Qt/Tools/mingw810_64\bin;%PATH%就能理解了,就是想系统变量PATH里追加两个路径D:\Qt\5.15.2\mingw81_64\binD:/Qt/Tools/mingw810_64\bin。这里可以自行测试验证。

注意,这里的设置系统变量,是临时性的,仅此次运行有效。所以不会永久修改了系统变量。

  1. 这段就好理解了,切换目录到D:\Qt\5.15.2\mingw81_64
cd /D D:\Qt\5.15.2\mingw81_64

可以理解为在使用windeployqt命令之前,进行了一些环境配置。

执行windeployqt

这一步没什么可说的,就是调用windeployqt.exe对程序进行依赖库的寻找并拷贝到程序当前路径下。

其实,windeployqt 还有一些选项,见help

D:\Qt\5.15.2\mingw81_64\bin>windeployqt.exe
Please specify the binary or folder.

Usage: windeployqt.exe [options] [files]
Qt Deploy Tool 5.15.2

The simplest way to use windeployqt is to add the bin directory of your Qt
installation (e.g. <QT_DIR\bin>) to the PATH variable and then run:
  windeployqt <path-to-app-binary>
If ICU, ANGLE, etc. are not in the bin directory, they need to be in the PATH
variable. If your application uses Qt Quick, run:
  windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>

Options:
  -?, -h, --help              Displays help on commandline options.
  --help-all                  Displays help including Qt specific options.
  -v, --version               Displays version information.
  --dir <directory>           Use directory instead of binary directory.
  --libdir <path>             Copy libraries to path.
  --plugindir <path>          Copy plugins to path.
  --debug                     Assume debug binaries.
  --release                   Assume release binaries.
  --pdb                       Deploy .pdb files (MSVC).
  --force                     Force updating files.
  --dry-run                   Simulation mode. Behave normally, but do not
                              copy/update any files.
  --no-patchqt                Do not patch the Qt5Core library.
  --ignore-library-errors     Ignore errors when libraries cannot be found.
  --no-plugins                Skip plugin deployment.
  --no-libraries              Skip library deployment.
  --qmldir <directory>        Scan for QML-imports starting from directory.
  --qmlimport <directory>     Add the given path to the QML module search
                              locations.
  --no-quick-import           Skip deployment of Qt Quick imports.
  --translations <languages>  A comma-separated list of languages to deploy
                              (de,fi).
  --no-translations           Skip deployment of translations.
  --no-system-d3d-compiler    Skip deployment of the system D3D compiler.
  --compiler-runtime          Deploy compiler runtime (Desktop only).
  --no-virtualkeyboard        Disable deployment of the Virtual Keyboard.
  --no-compiler-runtime       Do not deploy compiler runtime (Desktop only).
  --webkit2                   Deployment of WebKit2 (web process).
  --no-webkit2                Skip deployment of WebKit2.
  --json                      Print to stdout in JSON format.
  --angle                     Force deployment of ANGLE.
  --no-angle                  Disable deployment of ANGLE.
  --no-opengl-sw              Do not deploy the software rasterizer library.
  --list <option>             Print only the names of the files copied.
                              Available options:
                               source:   absolute path of the source files
                               target:   absolute path of the target files
                               relative: paths of the target files, relative
                                         to the target directory
                               mapping:  outputs the source and the relative
                                         target, suitable for use within an
                                         Appx mapping file
  --verbose <level>           Verbose level (0-2).

Qt libraries can be added by passing their name (-xml) or removed by passing
the name prepended by --no- (--no-xml). Available libraries:
bluetooth concurrent core declarative designer designercomponents enginio
gamepad gui qthelp multimedia multimediawidgets multimediaquick network nfc
opengl positioning printsupport qml qmltooling quick quickparticles quickwidgets
script scripttools sensors serialport sql svg test webkit webkitwidgets
websockets widgets winextras xml xmlpatterns webenginecore webengine
webenginewidgets 3dcore 3drenderer 3dquick 3dquickrenderer 3dinput 3danimation
3dextras geoservices webchannel texttospeech serialbus webview

Arguments:
  [files]                     Binaries or directory containing the binary.

总结

在进行打包之前,Qt进行了一些环境配置,才得以正确的打包。可以自行只调用windeployqt测试,会多少遇到奇怪的问题。

Windows 批处理(cmd/bat)常用命令教程

CMD.exe (Command Shell) - Windows CMD - SS64.com

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值