QT5 项目打包成 exe 程序

Table of Contents

1. TLDR: 使用 qt 安装

  1. 使用 Qt 自带的命令行工具,或使用 qtenv2.bat 来初始化环境变量

    C:\Qt\Qt5.14.2\5.14.2\mingw73_64\bin>qtenv2.bat
    Setting up environment for Qt usage...
    
  2. 使用 Qt 自带的命令行工具打包,或使用 windeployqt.exe 来初始化环境变量

    D:\...\untitled\release\dist>windeployqt app.exe
    

2. 打包实例

Microsoft Windows [版本 10.0.26100.2894]
(c) Microsoft Corporation。保留所有权利。

C:\Qt\Qt5.14.2\5.14.2\mingw73_64\bin>qtenv2.bat
Setting up environment for Qt usage...


D:\code\msvc\GUI\untitled>dir
 驱动器 D 中的卷是 DATA
 卷的序列号是 5645-DEB3

 D:\code\msvc\GUI\untitled 的目录

2025/01/20  09:02    <DIR>          .
2025/01/20  09:01    <DIR>          ..
2025/01/20  08:11             2,677 .clang-format
2025/01/20  08:33               935 .gitignore
2025/01/20  08:25             1,093 .qmake.stash
2025/01/20  09:02    <DIR>          debug
2025/01/20  08:11    <DIR>          include
2025/01/20  11:24            30,701 Makefile
2025/01/20  11:24            42,488 Makefile.Debug
2025/01/20  11:24            42,586 Makefile.Release
2025/01/20  08:11               217 readme.org
2025/01/20  11:24    <DIR>          release
2025/01/20  08:11    <DIR>          src
2025/01/20  08:32             1,071 untitled.pro
2025/01/20  09:02            22,627 untitled.pro.user
               9 个文件        144,395 字节
               6 个目录 845,593,976,832 可用字节


D:\code\msvc\GUI\untitled\release\dist>dir
 驱动器 D 中的卷是 DATA
 卷的序列号是 5645-DEB3

 D:\code\msvc\GUI\untitled\release\dist 的目录

2025/01/20  11:24    <DIR>          .
2025/01/20  11:24    <DIR>          ..
2025/01/20  11:24            25,600 app.exe
               1 个文件         25,600 字节
               2 个目录 845,593,976,832 可用字节

D:\code\msvc\GUI\untitled\release\dist>windeployqt app.exe
D:\code\msvc\GUI\untitled\release\dist\app.exe 64 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Direct dependencies: Qt5Core Qt5Widgets
All dependencies   : Qt5Core Qt5Gui Qt5Widgets
To be deployed     : Qt5Core Qt5Gui Qt5Svg Qt5Widgets
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.
Updating libgcc_s_seh-1.dll.
Updating libstdc++-6.dll.
Updating libwinpthread-1.dll.
Creating directory D:/code/msvc/GUI/untitled/release/dist/iconengines.
Updating qsvgicon.dll.
Creating directory D:/code/msvc/GUI/untitled/release/dist/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:/code/msvc/GUI/untitled/release/dist/platforms.
Updating qwindows.dll.
Creating directory D:/code/msvc/GUI/untitled/release/dist/styles.
Updating qwindowsvistastyle.dll.
Creating D:\code\msvc\GUI\untitled\release\dist\translations...
Creating qt_ar.qm...
Creating qt_bg.qm...
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_da.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_es.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_gd.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...
Creating qt_zh_TW.qm...

D:\code\msvc\GUI\untitled\release\dist>

Last Updated 2025-01-20 Mon 11:38. Created by Jinghui Hu at 2025-01-20 Mon 00:00.