Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are QT platform dlls supposed to go?

Tags:

dll

qt

qt5

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

like image 856
Jacob Schoen Avatar asked Mar 24 '23 18:03

Jacob Schoen


2 Answers

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.

like image 140
Jacob Schoen Avatar answered Mar 26 '23 07:03

Jacob Schoen


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.

like image 30
phyatt Avatar answered Mar 26 '23 09:03

phyatt