Waq*_*ish 10 c++ visual-studio-2010 windows-7-x64 qt5
我在Windows 7 x64下的VS 2010中静态构建了Qt 5.0.1.配置参数是
configure -debug-and-release -opensource -confirm-license -platform win32-msvc2010 -nomake examples -nomake tests -no-webkit -static
Run Code Online (Sandbox Code Playgroud)
我使用以下参数执行带有jom的构建:
jom -j 4
Run Code Online (Sandbox Code Playgroud)
构建过程是成功的,我可以找到所有的库并静态链接我的应用程序与Qt.现在的问题是,当我尝试运行应用程序时,它给了我一个错误
Module: 5.0.1
File: kernel\qguiapplication.cpp
Line: 781
"Failed to load platform plugin "windows". Available platforms are:"
Run Code Online (Sandbox Code Playgroud)
但是在此错误之下,它不会显示任何平台.我在动态链接Qt时遇到了同样的错误.我通过将依赖DLL(qt5core.dll,qt5gui.dll等)放在我的exe的同一目录中来摆脱它.但这次我想不出办法.
在静态构建Qt之后,plugins/platforms /文件夹中的DLL消失了,它们被libs取代.我也尝试静态链接qwindows.lib但无济于事.
任何的想法?问候.
要检查在Windows上部署应用程序所需的DLL,请使用dependency Walker(http://www.dependencywalker.com/).
根据文档页面Qt for Windows - 部署需要一些DLL来在Windows平台上部署Qt应用程序:
根据用于编译应用程序的编译器,可能还需要一些其他库:
注意:在所有这些文件中,将XX替换为系统上当前版本的DLL.
如果您没有静态构建Qt(默认),您还需要Qt5 DLL,具体取决于您在应用程序中使用的Qt模块.例:
所有这些DLL都可以在你的Qt安装目录下的"bin"文件夹中找到.
最近,Qt开发人员创建了一个名为windeployqt.exe的工具,它可以帮助您收集部署应用程序所需的所有库:
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.
Run Code Online (Sandbox Code Playgroud)
我只是遇到了同样的问题,所以这是我的解决方案:
当然,首先使用-static参数构建QT。
将以下库添加到您的构建中:
Qt5PlatformSupport.lib
qwindows.lib
imm32.lib
Run Code Online (Sandbox Code Playgroud)
将以下路径添加到您的库路径:
$(QTDIR)\plugins\platforms
Run Code Online (Sandbox Code Playgroud)
在您的代码(最好是main.cpp)中添加以下行:
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
Run Code Online (Sandbox Code Playgroud)
生成的版本不应该依赖于任何与Qt相关的dll。