33

I am writing a Qt application on Windows using Visual Studio 2012. Using the Qt Add-in and a custom built static distribution of Qt 5.0.2. I am running into the dreaded "Failed to load platform plugin windows" error whenever I run the application. I have added the following to the linker input:

imm32.lib
winmm.lib
Ws2_32.lib
qtmaind.lib
Qt5Cored.lib
Qt5Guid.lib
Qt5Widgetsd.lib

At first I thought that maybe I should add "qwindowsd.lib" to that list as well however that did not fix the problem. What do I need to do in order to make my application run?

Rappel
  • 696
  • 2
  • 6
  • 14
Dave
  • 7,283
  • 12
  • 55
  • 101

10 Answers10

31

For dynamic build only: Make sure you move the qwindows.dll to the following directory:

yourapp.exe
Qt5Core.dll
...
platforms/qwindows.dll
...

Note that the plugins directory is missing! You put all the needed folders from QT_BASE/.../plugins/* directly together with your binaries. BTW: I did not need libEGL.dll, but my application almost has no GUI.

My source: http://qt-project.org/forums/viewthread/27056/#122588

adler
  • 949
  • 1
  • 9
  • 10
  • Worked for me too. It would be nice to know how to let this deployment step working in CMake > 3. – linello Oct 22 '15 at 15:27
  • Thanks, I was copying by mistake only the dlls. I needed to copy the folder structure... – Leonardo Alves Machado Jun 14 '16 at 15:24
  • only this answer works for me, to add a folder: platforms/qwindows.dll , it contains this .dll; then everything is ok for the qt app. – vivi Jan 06 '17 at 14:56
  • Is there a way to cut off this 'platform integration' feature? QT4 did not require it. Why is it mandatory in QT5? – def Dec 22 '19 at 21:46
30

I solved it. Thanks to this I was able to get everything to work. I added the following libraries:

opengl32.lib
Qt5PlatformSupport.lib
qwindows.lib

I also added the following to my code:

#include <QtPlugin>
Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin);
Dave
  • 7,283
  • 12
  • 55
  • 101
  • 1
    How did you link qwindows.lib. The normal route of adding LIBS += qwindows.lib didn't find it. – mphair Feb 21 '14 at 13:48
  • 1
    Also unable to find qwindows.lib anywhere – jjxtra Jan 13 '15 at 18:26
  • 3
    @PsychoDad It's only available if you have built the static Qt libraries. With the normal builds downloaded from the Qt website, you just need to put the qwindows.dll (or qwindowsd.dll) shared library in the **platforms** subfolder next to your built executable. Make this subdirectory manually. Similarly you may need other plugins from imageformats, etc. depending on your program. – chappjc Jan 14 '15 at 23:32
  • @chappjc Your fix worked for me. I find it very odd that the missing DLL isn't detected or traceable via something like dependency walker. I find it equally odd that the same error message is solved by adding so many different DLL files depending on the project. Anyhow, thanks to you both for the answer to my problem. I guess the next thing is to figure out how to trace this a bit more easily or at least get the Qt owners to address and fix this. – soulsabr Feb 19 '16 at 15:45
  • @soulsabr I agree that it's strange that Dependency Walker couldn't identify this. – chappjc Feb 23 '16 at 22:11
  • How did you get the qwindows.lib and Qt5PlatformSupport.lib to build? I'm building with -static but they do not build. It seems qwindows platform requirers direct X? – Peter Mitrano Dec 31 '19 at 09:14
13

I had the same error with MinGW version of Qt (not static): "Failed to load platform plugin windows".

The solution for me was to add the DLLs libEGL.dll and libEGLd.dll.

nobody
  • 19,814
  • 17
  • 56
  • 77
dagur
  • 432
  • 4
  • 16
  • That did it for me: http://stackoverflow.com/questions/20495620/qt-5-1-1-application-failed-to-start-because-platform-plugin-windows-is-missi THANKS! – Anonymous Dec 10 '13 at 13:38
9

You could also make an environment variable:

QT_QPA_PLATFORM_PLUGIN_PATH=<QT_BASE>\plugins\platforms

which in my case becomes: QT_QPA_PLATFORM_PLUGIN_PATH=f:\Qt\5\5.4\msvc2013_opengl\plugins\platforms

Thus avoiding installing/copying qwindows.dll during development (to save disk-space!?).

This solution was also mentioned on GitHub and here.

EDIT: Sorry, this is not effective in a static build. But I'll leave my A here.

Community
  • 1
  • 1
G.Vanem
  • 111
  • 1
  • 5
6

Ok I had similar issue.

I found out that QT 5.2+ has windeployq.exe

QT_DIRECTORY\5.2...\bin\windeployq.exe

Use it with the directory of your project (where the .exe of your application is). And voilà ! Automatically linked everything and ready to deploy !

It will get the DLLs, Plugins etc... automatically !

Yves Lange
  • 3,914
  • 3
  • 21
  • 33
  • This should be the correct answer. Together with this link : http://doc.qt.io/qt-5/windows-deployment.html – crashdog Jan 20 '19 at 12:40
5

An alternative is to copy the qtbase/plugins/platforms directory into the Debug/Release directories leaving just qwindowsd.dll or qwindows.dll as appropriate.

darrenp
  • 4,265
  • 2
  • 26
  • 22
  • This is a static build. No DLL's, just a single exe file. – Dave Jun 29 '13 at 00:02
  • Ah I see. Hopefully this is useful to others who are using dlls. – darrenp Jul 11 '13 at 20:47
  • 1
    Yes, you almost right, but you have to put the "qwindowsd.dll" from "QtBase\plugins\platforms" to the "platforms\qwindowsd.dll" folder as adler said. Don't forget about relative path! – Maks Jul 02 '15 at 23:44
2

Starting with QT 5.9+ Qt5PlatformSupport.lib is no longer available and has been split into different libraries. To create a static build under windows one needs to link the following additional libraries:

Qt5FontDatabaseSupport.lib
Qt5EventDispatcherSupport.lib
Qt5ThemeSupport.lib
Qt5PlatformCompositorSupport.lib
Qt5AccessibilitySupport.lib
Qt5WindowsUiAutomationSupport.lib
qwindows.lib

and load the windows plugin statically:

#include <QtPlugin>
Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin);
nairboon
  • 678
  • 5
  • 15
1

The solutions is,if you are using anaconda and python to make a gui using qt designer then go to anaconda,pkgs,qt.xxx,library,plugins ,then copy the platforms folder to your build folder wich contains your program.exe

0

I exactly this probelm. The solution is to check the Qt in Debug output. That window tells you all the DLLs it loads. These are the ones you may need in your distribution exe folder.

0

I had the same error with VS2015 and the version of Qt 5.9.3

I solved the error by replacing the Qt5Cored.dll and Qt5Core.dll(where the exe of my application) with the same DLLs in Qt directory

JumHorn
  • 121
  • 5