Qt 5.x 应用程序 Windows 部署方法

使用 Qt 5.2.1 开发了一个程序之后,部署竟然用了我很长时间来调试。现在总算搞明白了。

1、源代码使用 UTF-8 编码格式,对于 VC++ 2010 来说,创建并引入头文件 charset.h:

#pragma once

// VC 2010 以后,要求源码设置 UTF-8 BOM
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
# pragma execution_character_set("utf-8")
#endif

只要是源代码中使用了中文,都要引入这个头文件。

使用 UTF-8,必须使用如下 DLL:

icudt51.dll
icuin51.dll
icuuc51.dll

2、必须的 DLL,比如:

Qt5Core.dll
Qt5Gui.dll
Qt5Network.dll
Qt5Sql.dll
Qt5Websockets.dll
Qt5Widgets.dll
...

3、VC++ 2010 Redistribution Package x86

4、由于 Qt 使用了 Qt 5.2.1 for Windows 32-bit (VS 2010, OpenGL, 517 MB) 这个版本,因此还需要

libEGL.dll
LibGLESv2.dll
D3DCompiler_43.dll

起初不知道需要这些文件,部署后总是报 This application failed to start because it could not find or load the Qt platform plugin "windows".


还以为是插件目录的问题,折腾了好久,总是不正确,后来在 QtCreator 目录中发现这些 dll,复制过来。


5、插件配置

⑴在应用程序 app.exe 目录下创建插件子目录,类似如下目录结构:

./bin/app.exe
./bin/platforms

将 Qt 系统目录中的相应子目录复制过来,文件包括:

qminimal.dll
qoffscreen.dll
qwindows.dll
...

⑵使用 Qt 设置库目录的 API:

QStringList libraryPaths = QStringList()
                               << qApp->applicationDirPath()
                               << qApp->applicationDirPath().append("/plugins");
QApplication::setLibraryPaths(libraryPaths);

或者:

QApplication::addLibraryPath(“./plugins”);

⑶使用资源文件 app.qrc,将 qt.conf 配置文件作为资源,加入路径 :/qt/etc/qt.conf,

Qt5Core.dll 加载时默认访问这个配置文件。


⑷使用外部 qt.conf 配置文件

qt.conf 放置于 app.exe 所在目录,内容如下:

[Paths]
Plugins=./plugins

6、总结,

以上设置如果不正确,从而找不到 platforms 目录时,会报  This application failed to start because it could not find or load the Qt platform plugin "windows".这个错误。

相关文档,请参考:

http://qt-project.org/doc/qt-5/windows-deployment.html
http://qt-project.org/doc/qt-5/windows-issues.html
http://qt-project.org/doc/qt-5/deployment-plugins.html



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值