C++ 应用程序无法启动,因为它无法找到或加载 QT 平台插件“windows”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21268558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:35:04  来源:igfitidea点击:

Application failed to start because it could not find or load the QT platform plugin "windows"

c++qtdllplatform

提问by gollumullog

I have looked through all of the questions that appear to be related on stack overflow, and none of the solutions seem to help me.

我已经查看了似乎与堆栈溢出相关的所有问题,但似乎没有任何解决方案对我有帮助。

I am building a Qt application with this setup:

我正在使用此设置构建 Qt 应用程序:

  • Windows 7 Professional x64
  • Visual Studio 2012
  • Qt 5.2.0 built with configure -developer-build -debug-and-release -opensource -nomake examples -nomake tests -platform win32-msvc2012 -no-opengl
  • Project uses QtSingleApplication (qt-solutions)
  • Application is a 32 bit application
  • qmake run with the following: -makefile -spec win32-msvc2012
  • .pri uses QMAKE_CXX += /D_USING_V110_SDK71_
  • Windows 7 专业版 x64
  • 视觉工作室 2012
  • Qt 5.2.0 内置 configure -developer-build -debug-and-release -opensource -nomake examples -nomake tests -platform win32-msvc2012 -no-opengl
  • 项目使用QtSingleApplication(qt-solutions)
  • 应用程序是 32 位应用程序
  • qmake 使用以下命令运行:-makefile -spec win32-msvc2012
  • .pri 使用 QMAKE_CXX += /D_USING_V110_SDK71_

I can build and run my program fine on my development machine (noted above); I can also install and run the package from Program Files directory on dev machine.

我可以在我的开发机器上很好地构建和运行我的程序(如上所述);我还可以从开发机器上的 Program Files 目录安装和运行包。

When I install and run on a Windows Vista machine (multiple machines)

当我在一台 Windows Vista 机器(多台机器)上安装并运行时

  • VC++ redist 2012 11.0.61030.0 installed
  • VC++ redist 2010 10.0.40219 installed
  • plus 2005, 2008 versions of redist
  • VC++ redist 2012 11.0.61030.0 已安装
  • VC++ redist 2010 10.0.40219 已安装
  • 加上 2005、2008 版本的 redist

(also fails on a clean install of Windows 7)

(在全新安装 Windows 7 时也会失败)

I get:

我得到:

Application failed to start because it could not find or load the QT platform plugin "windows"

Application failed to start because it could not find or load the QT platform plugin "windows"

So I followed the instructions and added a .platforms/ directory, and added qwindows.dll (also added qminimal.dll and qoffscreen.dll); I also added libEGL.dll, libGLESv2.dll (even though I shouldn't need them I don't think)

所以我按照说明添加了一个.platforms/目录,并添加了qwindows.dll(也添加了qminimal.dll和qoffscreen.dll);我还添加了 libEGL.dll、libGLESv2.dll(即使我不应该需要它们,我认为)

Once I added qoffscreen.dll I now get the additional message: Available platform plugins are: offscreen

添加 qoffscreen.dll 后,我现在收到附加消息: Available platform plugins are: offscreen

If I run through Dependency Walker I get this error listed:

如果我运行 Dependency Walker,则会列出以下错误:

GetProcAddress(0x76CA0000 [KERNEL32.DLL], "GetCurrentPackageId") called from "MSVCR110.DLL" at address 0x6AC6FDFA and returned NULL. Error: The specified procedure could not be found (127).

and then further down get the:

然后进一步向下得到:

GetProcAddress(0x745A0000 [UXTHEME.DLL], "BufferedPaintUnInit") called from "COMCTL32.DLL" at address 0x745FFBF8 and returned 0x745AE18C.
This application failed to start because it could not find or load the Qt platform plugin "windows".

Available platform plugins are: offscreen.

Reinstalling the application may fix this problem.

Any ideas how to fix this dll issue?

任何想法如何解决这个dll问题?

采纳答案by gollumullog

Well I solved my issue, although I'm not sure what the difference is:

好吧,我解决了我的问题,虽然我不确定有什么区别:

I copied every dll from my qt directory into both ./ and ./platforms of my application directory.

我将 qt 目录中的每个 dll 都复制到了应用程序目录的 ./ 和 ./platforms 中。

The application got past the error, but then crashed.

应用程序克服了错误,但随后崩溃了。

VERSION.dll was causing the crash (noted in dependency walker), so I removed it from both places.

VERSION.dll 导致了崩溃(在dependency walker 中注明),所以我从两个地方都删除了它。

The Application started up, so I systematically removed all unneeded dll's.

应用程序启动了,所以我系统地删除了所有不需要的 dll。

This got me back to the same state I had originally.

这让我回到了最初的状态。

I then uninstalled my application and re-installed (with only the ./platforms/qwindows.dll file remaining), application works correctly.

然后我卸载了我的应用程序并重新安装(只剩下 ./platforms/qwindows.dll 文件),应用程序正常工作。

So all I can assume is that I had an incorrect version of qwindows.dll in the platforms directory.

所以我只能假设我在平台目录中有一个不正确的 qwindows.dll 版本。

回答by Jan Moritz

The error is caused because the program can't find qwindows.dll

错误是因为程序找不到 qwindows.dll

qwindows.dllhas to be in a folder named platformsso that the path from your executable to the dll is platforms/qwindows.dll

qwindows.dll必须位于命名的文件夹中,platforms以便从可执行文件到 dll 的路径为platforms/qwindows.dll

Whereas this wasn't enough in my case. I had also to add following line at the beginning of my main()

而在我的情况下,这还不够。我还必须在 main() 的开头添加以下行

QCoreApplication::addLibraryPath("./");

Then everything worked.

然后一切正常。

回答by Orest Hera

The application is able to run on the host system, since the Qt binpath is in the system PATHvariable.

该应用程序能够在主机系统上运行,因为 Qtbin路径在系统PATH变量中。

There is a standard Qt tool for deployment of Qt applications on Windows windeployqtto be able to run the application on target machines that do not have Qt installed.

有一个标准的 Qt 工具用于在 Windows 上部署 Qt 应用程序,windeployqt以便能够在未安装 Qt 的目标机器上运行该应用程序。

That tool takes care about Qt DLL dependencies, makes a copy of platforms\qwindows.dlland also it makes a copy of libraries that you cannot detect with the Dependency Walker, since image plugins and some other DLLs are loaded at runtime.

该工具负责处理 Qt DLL 依赖项,制作一个副本,platforms\qwindows.dll并制作您无法使用Dependency Walker检测到的库的副本,因为图像插件和其他一些 DLL 是在运行时加载的。

You do not even need to have your Qt binfolder in your environment PATH. The simplest deployment:

你甚至不需要bin在你的环境中有你的 Qt文件夹PATH。最简单的部署:

  • copy built exebinary to a new folder
  • open cmdconsole in that folder
  • call windeployqtusing the full path (if it is not in the system PATH) and provide your executable, for example:
    c:\Qt\Qt5.2.1.2.1\msvc2010_opengl\bin\windeployqt.exe application.exe
    
  • 将构建的exe二进制文件复制到新文件夹
  • cmd在该文件夹中打开控制台
  • windeployqt使用完整路径调用(如果它不在系统中PATH)并提供您的可执行文件,例如:
    c:\Qt\Qt5.2.1.2.1\msvc2010_opengl\bin\windeployqt.exe application.exe
    

As a result you have in that folder all needed Qt DLLs to run the application.

因此,您在该文件夹中拥有运行应用程序所需的所有 Qt DLL。

The tool windeployqthas various options. It can also take care about deployment of qmlrelated files.

该工具windeployqt有多种选择。它还可以负责qml相关文件的部署。

Of course you can have also issues with MSVC redistributables, but those should be deployed separately and installed once per system.

当然,您也可能会遇到 MSVC 可再发行组件的问题,但这些组件应该单独部署,并为每个系统安装一次。

Only some 3rd party libraries should be copied manually if they are used, for example OpenSSL.

如果使用了某些 3rd 方库,则仅应手动复制它们,例如 OpenSSL。

回答by Lucian

I got this issue and how I solved it:

我遇到了这个问题以及我是如何解决它的:

  1. Used dependency walker(http://www.dependencywalker.com/) to see the exact path of the dlls needed. Try it because both QtCreator and QT framework both have the same dlls and you must pinpoint the exact ones used. I copied all dlls needed in the same folder as the app.

  2. I have copied the folder platforms from QT framework /plugins and copied it in the same folder as the app. Now the app comtained also plugin/platform/ folder with all its dlls

  3. And the most important step in my case is to create a file named qt.conf in the same folder as the app . This file should contain the path to the plugins. My qt.conf file contains:

    [Paths]
    Libraries=../lib/qtcreator
    Plugins=plugins
    Imports=imports
    Qml2Imports=qml

  1. 使用dependency walker(http://www.dependencywalker.com/)查看所需dll的确切路径。尝试一下,因为 QtCreator 和 QT 框架都具有相同的 dll,您必须确定使用的确切 dll。我将所有需要的 dll 复制到与应用程序相同的文件夹中。

  2. 我已经从 QT 框架 /plugins 复制了文件夹平台,并将其复制到与应用程序相同的文件夹中。现在该应用程序还包含 plugin/platform/ 文件夹及其所有 dll

  3. 就我而言,最重要的步骤是在 app 所在的文件夹中创建一个名为 qt.conf 的文件。此文件应包含插件的路径。我的 qt.conf 文件包含:

    [路径]
    库=../lib/qtcreator
    Plugins=plugins
    Imports=imports
    Qml2Imports=qml

回答by Amar

I had the same issue "Application failed to start because it could not find or load the QT platform plugin "windows" I fixed this by copying below files to the app.exe (my app executable) folder,

我遇到了同样的问题“应用程序无法启动,因为它无法找到或加载 QT 平台插件“windows”我通过将以下文件复制到 app.exe(我的应用程序可执行文件)文件夹来解决这个问题,

Qt5Core.dll, Qt5Gui.dll, Qt5Widgets.dll and a "platforms" directory with qminimal.dll, qoffscreen.dll, qwindows.dll.

Qt5Core.dll、Qt5Gui.dll、Qt5Widgets.dll 和带有 qminimal.dll、qoffscreen.dll、qwindows.dll 的“平台”目录。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

I hope this will help someone

我希望这会帮助某人

回答by Timmmm

Note this issue can alsobe caused if the search path for qwindows.dllthat is encoded in your app includes the path where you installed Qt. Consider the following scenario:

请注意,如果您的应用程序中编码的搜索路径包含您安装 Qt 的路径,可能导致此问题qwindows.dll。考虑以下场景:

  1. I install Qt to c:\Qt\...
  2. I develop an app and deploy it correctly somewhere else.
  3. It runs on any computer properly because it includes qwindows.dllin a subdirectory.
  4. I upgrade my local Qt to a new version.
  5. I try to run my app again.
  1. 我将 Qt 安装到 c:\Qt\...
  2. 我开发了一个应用程序并将其正确部署到其他地方。
  3. 它可以在任何计算机上正常运行,因为它包含qwindows.dll在一个子目录中。
  4. 我将本地 Qt 升级到新版本。
  5. 我尝试再次运行我的应用程序。

The result is this error, because the qwindows.dllin c:\Qt\...is found beforethe one in its local directory and it is incompatible with it. Very annoying.

结果是这个错误,因为在它的本地目录中找到了qwindows.dllin之前,并且与它不兼容。很烦人。c:\Qt\...

A solution is to place a file qt.confin the same directory as your exe file. I don't know how to avoid this. If you used the tool windeployqt.exeto deploy your app, so you have a subdirectory called platforms, then this is sufficient:

解决方案是将文件qt.conf放在与 exe 文件相同的目录中。我不知道如何避免这种情况。如果您使用该工具windeployqt.exe来部署您的应用程序,因此您有一个名为 的子目录platforms,那么这就足够了:

[Paths]
Plugins=.

回答by RuiDC

For me, I needed to setQT_QPA_PLATFORM_PLUGIN_PATHto the platforms directory and then it worked.

对我来说,我需要设置QT_QPA_PLATFORM_PLUGIN_PATH到平台目录然后它才能工作。

For what it's worth, this solution was also mentioned on GitHub.

对于它的价值,GitHub 上提到了这个解决方案。

回答by vc669

For the people who have this problem in the future - I have a dirty little hack, worked for me. Try at your own risk.

对于将来遇到这个问题的人 - 我有一个肮脏的小黑客,为我工作。请自担风险尝试。

Follow all the steps in Initial deployment (Quick and dirty) [http://wiki.qt.io/Deploy_an_Application_on_Windows]

按照初始部署(快速和肮脏)[ http://wiki.qt.io/Deploy_an_Application_on_Windows] 中的所有步骤进行操作

  1. Close Qt Creator.
  2. Copy the following into C:\Deployment\ The release version of MyApp.exe All the .dll files from C:\Qt\5.2.1\mingw48_32\bin\ All the folders from C:\Qt\5.2.1\mingw48_32\plugins\
  3. (If you used QML) All the folders from C:\Qt\5.2.1\mingw48_32\qml\ Rename C:\Qt\ to C:\QtHidden\ (This turns your PC into a clean environment, just like one that doesn't have Qt installed).
  4. Launch C:\Deployment\MyApp.exe.
  1. 关闭 Qt Creator。
  2. 将以下内容复制到 C:\Deployment\ MyApp.exe 的发行版 C:\Qt\5.2.1\mingw48_32\bin\ 中的所有 .dll 文件 C:\Qt\5.2.1\mingw48_32\ 中的所有文件夹插件\
  3. (如果您使用 QML) C:\Qt\5.2.1\mingw48_32\qml\ 中的所有文件夹 将 C:\Qt\ 重命名为 C:\QtHidden\(这会将您的 PC 变成一个干净的环境,就像没有没有安装 Qt)。
  4. 启动 C:\Deployment\MyApp.exe。

Now for the hack -

现在为黑客 -

  1. Duplicate your folder for safety
  2. If your file was in /cat/Deployment, go to /cat
  3. Now, delete the Deployment folder while the .exe is still running.
  4. It will tell you that it cannot delete certain files, so say Skip(or skip all)
  5. What you're left with is the list of all the .dll files that your .exe was actually using and could not delete: the list of all the files and only the files that you need to keep.
  1. 复制您的文件夹以确保安全
  2. 如果您的文件在 /cat/Deployment 中,请转到 /cat
  3. 现在,在 .exe 仍在运行时删除 Deployment 文件夹。
  4. 它会告诉你它不能删除某些文件,所以说跳过(或跳过所有)
  5. 剩下的是您的 .exe 实际使用且无法删除的所有 .dll 文件的列表:所有文件的列表以及您需要保留的文件。

You can close the .exe file now. To check whether it is deploying okay, go into the folder where you installed it, say C:/Qt and rename it to C:/NotQt (basically make Qt invisible to the system). If it works now, it will deploy on other systems more often than not.

您现在可以关闭 .exe 文件。要检查它是否部署正常,请进入安装它的文件夹,说 C:/Qt 并将其重命名为 C:/NotQt(基本上使 Qt 对系统不可见)。如果它现在有效,它将经常部署在其他系统上。

回答by chime

I got the same issue: 1. it can run in VS2010; 2. it can run in a folder with files as: app.exe \platforms\qwindows.dll ...

我遇到了同样的问题: 1. 它可以在 VS2010 中运行;2.它可以在一个文件夹中运行,文件为:app.exe \platforms\qwindows.dll ...

  1. but it failed to load qwindows on a clean machine with same OS as the developing one.
  1. 但它无法在与开发中的操作系统相同的干净机器上加载 qwindows。

Solved simply by move the platform folder to plugins: app.exe plugins\platforms\qwindows.dll

只需将平台文件夹移动到插件即可解决:app.exe plugins\platforms\qwindows.dll



plus: qwindows.dll can be renamed as any you like as it is queried by an plugin interafce: qt_plugin_query_metadata()

另外:qwindows.dll 可以重命名为任何你喜欢的,因为它是由插件接口查询的:qt_plugin_query_metadata()

回答by Ruud van Gaal

It's missing qwindows.dll, which normally should be in platforms, unless you add:

它缺少 qwindows.dll,它通常应该在平台中,除非您添加:

QCoreApplication::addLibraryPath("<yourpath>");

If you don't do this btw, and put your qwindows.dll somewhere else, Qt will search your PATH for the DLL, which may take a LOT of time (10s - several minutes)!

顺便说一句,如果您不这样做,并将您的 qwindows.dll 放在其他地方,Qt 将在您的 PATH 中搜索 DLL,这可能需要很多时间(10 秒 - 几分钟)!