I have created a DLL that uses some functionality from QTWebKit, that I then access through JNA on the java side. On my machine (which QT is installed on obviously) it works fine. When I move it to another machine to to test it that does not have qt installed I get:
Failed to load platform plugin "windows". Available platforms are:
My google fu as pointed me to the fact that I need to also include platform DLLs, namely qwindows.dll
and qminimal.dll
. According to the QT5 documentation in Deploying an Application on Windows it sounds like when deploying an executable it would be in a folder called platforms
in the save directory as the executable.
In contrast to user plugins, Qt plugins have to be put into subdirectories matching the plugin type. As we want to deploy the windows platform plugin it has to be put into a "platforms" subdirectory.
That leads me to my dilemma. I have a dll, not an executable. So I have no clue where to put the platform folder. I have tried to place it in the same directory I am executing my test application, but that did not work.
So where do I place the platform directory in order for QT to be able to find it?
Edit: Since I have not had much feedback, maybe there is a better way to word/approach this question.
How do I tell QT where to find the platform DLLs?
It seems like there has to be a way to accomplish this. When I run it on my machine, it ends up looking in C:\Qt2\Qt5.0.2\5.0.2\msvc2012_64\plugins\platforms
. So it seems there m
I have found two possible solutions for the scenario that you need to create a
QApplication
inside a DLL or library (basically different from the normal create Qt application that has an exe).The easiest solution is to set the system environment variable
QT_QPA_PLATFORM
to the folder that you expect theplatforms
to be located at. I did not like this solution do to the fear that it could interfere with other applications installed on the end system.The next solution is to take advantage of the command line parameters that a normal QT application would use. In a normal Qt application
QApplication
would be created in your main similar to:Well we have to create
argv
andargc
anyway at this point so use that to our advantage.NOTE: Even now googling for
-platformpluginpath
I could not find any information for it. Or information on what other command line parameters may be available to use with QT. I found it by digging into the QT source code while looking for a solution. So if anyone happens to have a link to a resource with that information it would be handy to leave a comment with it.http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx#standard_search_order_for_desktop_applications
When you are running your program in Qt, it adjusts the environment variables to add some stuff on to your path.
The default "path" that your dll is aware of when it is being ran depends on the exe that loads it, and its working directory, its application directory, etc. If you test program that is loading your dll, is in the same folder as the dll, you probably just need to put
qwindows.dll
in "./platforms/".You also should check into this function:
http://qt-project.org/doc/qt-4.8/qcoreapplication.html#setLibraryPaths
http://qt-project.org/doc/qt-4.8/qcoreapplication.html#libraryPaths
Hope that helps. Good luck.