Where should the QT platform DLL be planned?

I created a DLL that uses some functions from QTWebKit, which I then get through JNA on the java side. On my machine (on which QT is installed explicitly) it works fine. When I transfer it to another machine to check it that does not have qt, I get:

Failed to load the windows plugin. Available platforms:

My google fu pointed out to me that I also need to include the DLLs, namely qwindows.dll and qminimal.dll . According to the QT5 documentation in β€œDeploying an Application on Windows,” it appears that when you deploy the executable, it will be located in the folder named platforms in the save folder as the executable.

Unlike custom plugins, Qt plugins must be placed in subdirectories corresponding to the type of plugin. Since we want to deploy the Windows platform plugin, it must be placed in the "platforms" subdirectory.

This brings me to my dilemma. I have a dll, not an executable. Therefore, I do not know where to place the folder with the platform. I tried to put it in the same directory in which I am running my test application, but this did not work.

So where to put the platform directory so QT can find it?

Edit: Since I did not have much feedback, perhaps there is a better way to tell / approach this question.

How to find out QT, where to find DLL platforms?

There seems to be a way to do this. When I run it on my machine, it finishes the search in C:\Qt2\Qt5.0.2\5.0.2\msvc2012_64\plugins\platforms . So it seems that m

+4
source share
3 answers

I found two possible solutions for the scenario that you need to create QApplication inside a DLL or library (basically different from a regular Qt application with exe).

  • The easiest solution is to set the system environment variable QT_QPA_PLATFORM to the folder in which you want to find platforms . I did not like this solution, fearing that it might interfere with other applications installed on the final system.

  • The next solution is to use the command line options that a regular QT application will use. In a regular Qt application, QApplication will be created in your mostly similar to:

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

    Well, in any case, we need to create argv and argc , so use this 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 about what other command line options may be available for use with QT. I found it, delving into the QT source code, looking for a solution. Therefore, if someone has a link to a resource with this information, it would be convenient to leave a comment with him.

+4
source

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx#standard_search_order_for_desktop_applications

When you run your program in Qt, it sets up environment variables to add some things to your path.

By default, the "path" that your dll knows about when it executes depends on the exe that loads it, and its working directory, its application directory, etc. If you are testing a program that loads your DLL, is in the same folder as the dll, you probably just need to put qwindows.dll in "./platforms/".

You should also check 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 this helps. Good luck.

+3
source

The documentation for QGuiApplication::QGuiApplication describes the supported command line arguments and the corresponding environment variables (if any). he deserves a mention.

and @jschoen, this is also a necessary link.

ps. my reputation is less than 50, so I can not comment on @jschoen

0
source

Source: https://habr.com/ru/post/1483647/


All Articles