在 Windows系统上,由于Qt社区版应用程序只能以动态链接库(dll)的形式发布,所有在发布Qt开发的应用程序时,需要复制相应的动态链接库。
Qt 官方提供了一个 Windows 部署工具 —— windeployqt,这个工具在 “QTDIR/bin/windeployqt” 路径下。它能够自动创建一个包含所有库、导入QML,插件、翻译等运行应用程序所需要的所有相关文件的可部署文件夹。

Usage: windeployqt [options] [file]
Qt Deploy Tool 5.3.0

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 this help.
  -v, --version             Displays version information.
  --dir <directory>         Use directory instead of binary directory.
  --libdir <path>           Copy libraries to path.
  --debug                   Assume debug binaries.
  --release                 Assume release binaries.
  --force                   Force updating files.
  --dry-run                 Simulation mode. Behave normally, but do not
                            copy/update any files.
  --no-plugins              Skip plugin deployment.
  --no-libraries            Skip library deployment.
  --qmldir <directory>      Scan for QML-imports starting from directory.
  --no-quick-import         Skip deployment of Qt Quick imports.
  --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-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.
  --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.

Qt libraries can be added by passing their name (-xml) or removed by passing
the name prepended by --no- (--no-xml). Available libraries:
bluetooth clucene concurrent core declarative designercomponents designer gui
clucene qthelp multimedia multimediawidgets multimediaquick network nfc opengl
positioning printsupport qml quick quickparticles script scripttools sensors
serialport sql svg test widgets winextras xml xmlpatterns

Arguments:
  [file]                    Binary or directory containing the binary.

使用方法

下面演示一个Qt Widgets Application可执行程序的发布方式:

  1. 找到想要发布的程序,假设文件名为HellWord.exe,把它复制到一个单独的文件夹(E:deployment);
  2. 打开Qt命令行工具,这里为“Qt 5.3.0 32-bit for Desktop (MSVC 2013)”,实际名以Qt版本为主;
  3. 在Qt命令行工具中输入“cd E:deployment”(不包括引号),进入“E:deployment”文件夹;
  4. 输入命令“windeployqt HellWord.exe”,等待命令结束。

最后得到的环境树如下图:

windeployqt结果

文件夹里的qm文件是多国语言翻译文件,不需要可以删掉。

如果要发布 Qt Quick Application 程序使用命令 windeployqt helloqml.exe --qmldir D:\Qt\Qt5.3.0\5.3\msvc2013\qml 。其中 D:\Qt\Qt5.3.0\5.3\msvc2013 是Qt安装目录(QTDIR),请根据实际机器上的实际目录修改。

上面是最简单的应用程序发布过程,实际项目中还需要加入自己程序关联的资源文件、数据库文件、配置文件等。

标签: Qt, windeployqt, Qt 部署

添加新评论