我们使用QT制作GUI软件,最终的目的是脱离开发环境,拿到其他电脑上运行使用。程序构建完毕,会在工程目录下生成一个exe可执行文件(windows平台为exe,linux为可执行文件)。而这个可执行文件一般是无法独立运行的(静态编译除外),还必须将exe所依赖的dll库及运行环境同exe文件打包才能运行。

在window中,QT提供了一个打包工具windeployqt,(在linux中的qt也有打包工具——linuxdeployqt,一般需要自己额外下载安装)它可以根据可执行文件的依赖关系,自动打包相应的依赖库及运行环境。 下面以windows为例,介绍其用法:

1. 首先在开始菜单中可以找到Qt x.x for Desktop(MinGW x.x.x xx bit),点击运行,会弹出cmd窗口,如下图所示。

           

2. 将需要发布的exe文件拷贝至新建的的空文件夹目录。

3. 在cmd窗口中输入cd /d [发布文件夹路径] ,进入exe所在的目录。

4. 输入 windeployqt xxx.exe 即可自动打包程序运行环境。

5. 双击运行planets-qml.exe,结果如下图所示,无法正常运行。

一般widget工程程序按照如上操作打包程序都能够正常运行。此处是因为该程序用到qml,与qml相关的依赖没有打包进来,导致程序无法正常运行。

查看windeployqt用法:

D:\Qt\Qt5.8.0\5.8\mingw53_32>windeployqt --help
Usage: windeployqt [options] [files]
Qt Deploy Tool 5.8.0The 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.--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 notcopy/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.--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 filestarget:   absolute path of the target filesrelative: paths of the target files, relativeto the target directorymapping:  outputs the source and the relativetarget, suitable for use within anAppx 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 designer designercomponents
enginio gui qthelp multimedia multimediawidgets multimediaquick network nfc
opengl positioning printsupport qml qmltooling quick quickparticles quickwidgetsscript scripttools sensors serialport sql svg test webkit webkitwidgets
websockets widgets winextras xml xmlpatterns webenginecore webengine
webenginewidgets 3dcore 3drenderer 3dquick 3dquickrenderer 3dinput geoservices
webchannel texttospeech serialbusArguments:[files]                   Binaries or directory containing the binary.

结果发现需要添加--qmldir <directory>选项,指定qml文件所在目录。

6. 重新清空文件夹,只剩xxx.exe文件,执行如下命令(--qmldir 一般指定为工程所用qml文件所在目录),重新进行打包:

执行打包完毕,可以明显发现依赖库多了许多。

7. 双击运行程序,程序能够正常运行。 经测试,将该文件夹拷贝至无QT环境的其他电脑,也能够正常运行。

windeployqt发布QT程序相关推荐

  1. win系统发布Qt程序——应用程序无法正常启动(0xc000007b)

    win系统发布Qt程序--应用程序无法正常启动(0xc000007b) 初步判断是库的问题 先确定windeploqt 匹配 比如我电脑上安装有不同构建工具的QT mingw73_32/ mingw7 ...

  2. 在Linux下使用linuxdeployqt发布Qt程序

    一.简介 linuxdeployqt 是Linux下的qt打包工具,可以将应用程序使用的资源(如库,图形和插件)复制到二进制运行文件所在的文件夹中. 二.安装linuxdeployqt 去github ...

  3. windows下发布Qt程序

    From: http://hi.baidu.com/limingfantasy/blog/item/22f6c459b8720086810a182e.html windows下发布Qt程序 2008- ...

  4. 麒麟系统开发笔记(八):在国产麒麟系统上使用linuxdeployqt发布qt程序

    若该文为原创文章,转载请注明原文出处 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/127484901 红胖子(红模仿)的博文大全:开发技术集 ...

  5. Mac 系统发布QT程序时,sqllite无法找到数据库,路径设置问题。

    Mac 系统发布QT程序时,sqllite无法找到数据库的问题,路径设置问题. Mac写的qt程序,使用了sqllite数据库,Qt里面release运行时可以连接数据库,正常使用.但是当运行rele ...

  6. windows平台下发布QT程序

    问题:我们已经编译出来了exe文件,发布时不知道需要依赖哪些库 第一种方法:windeployqt.exe 1.使用Everything查找 windeployqt.exe 找到windeployqt ...

  7. 【Qt】在ubuntu上打包发布Qt程序,可以不依赖Qt环境

    参考博客 https://blog.csdn.net/theArcticOcean/article/details/68069964 https://blog.csdn.net/hjl_1991/ar ...

  8. linux下 发布qt程序,Linux下发布qt程序

    安装patchelf 百度搜索,然后解压 进入文件夹用终端打开 然后执行命令: ./configure make sudo make install 编译linuxdeployqt 源码下载地址: h ...

  9. Linux下解决发布Qt程序报错:it could not find or load the Qt platform plugin “xcb” in “”

    简述 用Qt5.8版本在ubuntu16.04版本下编写Qt应用程序,生成release版本并打包,到另一台无Qt环境的linux系统中运行. 网上通常是按以下几个步骤进行: 1.生成release程 ...

最新文章

  1. linux进程间通信:POSIX 消息队列
  2. Spark环境搭建(一)-----------HDFS分布式文件系统搭建
  3. EasyUI-DataGrid之批量删除
  4. Python学习之参数(一)
  5. 《JavaScript高级程序设计》阅读笔记(七):ECMAScript中的语句
  6. 综合示例:自动生成一组新闻
  7. Leetcode--150. 逆波兰表达式求值
  8. Python程序异常处理:try、except、else、finally,捕获指定异常类型、捕获多个异常类型、捕获所有异常类型、捕获异常信息、异常的传递、raise抛出自定义异常
  9. java vc_vc++与 java有什么不同
  10. DoWhile(Java)
  11. 全国统考计算机网考题库,全国统考计算机网考题库教程.doc
  12. linux dnf配置文件,RedHat8.1配置本地dnf源
  13. 2021-2027全球与中国汽车传动轴联轴器市场现状及未来发展趋势
  14. matlab极坐标系作图,matlab极坐标作图
  15. “泰迪杯”挑战赛 - 基于非侵入式负荷检测与分解的电力数据挖掘(附详细数据及代码)
  16. linux coreclr编译,.NET跨平台:在Linux Ubuntu上编译coreclr/corefx/dnx(20150617)
  17. 浅析GPU通信技术(上)-GPUDirect P2P
  18. 优维低代码:Pipes 管道
  19. 系统架构设计师论文历年考题(2015-2017)考前冲刺来一波真题
  20. root后还能解除吗,root能不能完全解除

热门文章

  1. makemigrations 和 migrate工作原理分别是什么
  2. 谁有软件开发由航母最后变小破船的搞笑图
  3. python下载图片脚本_[python]非常小的下载图片脚本(非通用)
  4. 领域驱动DDD在签到场景落地案例之架构模式(二)
  5. 自然二进制码与格雷码相互转换【CSDN】
  6. 【C++】1049:晶晶赴约会(信息学奥赛)
  7. Android 支付宝快捷支付集成及ALI64错误的有效解决
  8. 当 Erda 遇上 API 生命周期管理,好戏开始了!
  9. JAVA中字符串使用GBK编码
  10. JavaScript------你真的会用console来调试打印么?