4

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

Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102

2 Answers2

4

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).

  1. The easiest solution is to set the system environment variable QT_QPA_PLATFORM to the folder that you expect the platforms 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.

  2. 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:

    int main(int argc, char *argv[]) {
       QApplication app(argc, argv);
    
       //other code
    
       return app.exec();
    }
    

    Well we have to create argv and argc anyway at this point so use that to our advantage.

    char *argv[] = {"YourAppName","-platformpluginpath", "C:/your/path/to/dll/folder", NULL};
    int argc = sizeof(argv) / sizeof(char*) - 1;
    
    QApplication app(argc, argv);
    

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.

Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
  • I think QT_QPA_PLATFORM in your solution (1) should be QT_QPA_PLATFORM_PLUGIN_PATH (http://qt-project.org/forums/viewthread/22908) – c_k Feb 15 '14 at 16:05
3

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.

phyatt
  • 18,472
  • 5
  • 61
  • 80
  • The trick is that I am running a java application that is calling into the dll. Apparently it the `QApplication` instance considers teh `applicationDirPath()` to be the bin directory for my version of java. Not what java considers to be my working directory. I tried using `addLibraryPath()` in `QApplication` to set it to a known known directory, and placing them there. But I still get the same error above. Thanks for the help and links though, good info for sure. – Jacob Schoen May 30 '13 at 20:59
  • Have you queried Java's working directory, and application directory? Can you install your Qt dlls there? – phyatt May 30 '13 at 21:12
  • Also have you successfully loaded and ran the dll outside of java, like with just a c++ example? – phyatt May 30 '13 at 21:14
  • sorry missed your comments. The weird thing to me is that Java's working is the root of my project (I am using eclipse), but the application dir path is the bin directory of the java install. Placing the dlls in the java working directory does not seem to work. Placing them in the bin directory of the java install does work, but that is not really feasible for deployment. I tried `addLibraryPath` and `setLibraryPaths` with no success. – Jacob Schoen May 31 '13 at 12:58