Application failed to start because it could not find or load the QT platform plugin "windows"
The error is caused because the program can't find qwindows.dll
qwindows.dll
has to be in a folder named platforms
so that the path from your executable to the dll is platforms/qwindows.dll
Whereas this wasn't enough in my case. I had also to add following line at the beginning of my main()
QCoreApplication::addLibraryPath("./");
Then everything worked.
The application is able to run on the host system, since the Qt bin
path is in the system PATH
variable.
There is a standard Qt tool for deployment of Qt applications on Windows windeployqt
to be able to run the application on target machines that do not have Qt installed.
That tool takes care about Qt DLL dependencies, makes a copy of platforms\qwindows.dll
and 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.
You do not even need to have your Qt bin
folder in your environment PATH
. The simplest deployment:
- copy built
exe
binary to a new folder - open
cmd
console in that folder - call
windeployqt
using the full path (if it is not in the systemPATH
) and provide your executable, for example:c:\Qt\Qt5.2.1\5.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.
The tool windeployqt
has various options. It can also take care about deployment of qml
related files.
Of course you can have also issues with MSVC redistributables, but those should be deployed separately and installed once per system.
Only some 3rd party libraries should be copied manually if they are used, for example OpenSSL.
I got this issue and how I solved it:
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.
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
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