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

来源:互联网 发布:溢思得瑞人工智能 编辑:程序博客网 时间:2024/06/05 22:52

使用 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.dllicuin51.dllicuuc51.dll

2、必须的 DLL,比如:

Qt5Core.dllQt5Gui.dllQt5Network.dllQt5Sql.dllQt5Websockets.dllQt5Widgets.dll...

3、VC++ 2010 Redistribution Package x86

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

libEGL.dllLibGLESv2.dllD3DCompiler_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.dllqoffscreen.dllqwindows.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 0
原创粉丝点击