PDA

View Full Version : Deploying a QApplication inside a DLL -> platform plugin not found even if here



Aria-dvp
5th August 2020, 09:40
Hello everybody,

I am developing a C++ graphical project using Qt5.14.2 for the GUI.
This project has to be a DLL, because it's loaded in Microstation, a well known CAD software. Everything works fine on my computer, and the project is almost done. :D
I sucessfully managed to do what needs to be done for a DLL : my QApplication is a singleton, the event loop run in a different Qthread, etc. It works!

I first deployed the DLL on my own computer, thanks to windeployqt.exe, and it worked really fine.
Now the problem, I did the same deployment on a test machine, in order to simulate a production environment. Microstation shows me the well known error message "This application failed to start because not Qt platform plugin could be initialized", even if all the Qt's DLLs are here. I suppose it worked on my computer because of QT_PATH. But now this path variable is no more, the project don't seems to find any of the Qt DLL deployed. Is it because they are not in the same folder as Microstation.exe?

Here my deployed folders :

Project folder
|- D3Dcompiler_47.dll
|- libEGL.dll
|- libGLESv2.dll
|- Myproject.dll
|- opengl32sw.dll
|- Qt5Core.dll
|- Qt5Gui.dll
|- Qt5Svg.dll
|- Qt5Widgets.dll
|
L___ iconengines
| |- qsvgicon.dll
|
L___ imageformats
| |- qgif.dll
| |- qicns.dll
| |- qico.dll
| |- qjpeg.dll
| |- qsvg.dll
| |- qtga.dll
| |- qtiff.dll
| |- qwbmp.dll
| |- qwebp.dll
|
L___ platforms
| |- qwindows.dll
|
L___ styles
| |- qwindowsvistastyle.dll
|
L___ translations
|- qt_ar.qm
|- qt_bg.qm
|- qt_ca.qm
|- qt_cs.qm
|- qt_da.qm
|- qt_de.qm
|- qt_en.qm
|- qt_es.qm
|- qt_fi.qm
|- qt_fr.qm
|- qt_gd.qm
|- qt_he.qm
|- qt_hu.qm
|- qt_it.qm
|- qt_ja.qm
|- qt_ko.qm
|- qt_lv.qm
|- qt_pl.qm
|- qt_ru.qm
|- qt_sk.qm
|- qt_uk.qm
|- qt_zh_TW.qm

How should I deploy the dll in order to make my project viable on a production environnement, without touching the Microstation installation folders?
I tried to follow the answer posted here (https://stackoverflow.com/questions/16843303/where-are-qt-platform-dlls-supposed-to-go/29000781#29000781)by adding the -platformpluginpath in the argv plus the platforms folder's path, but this doesn't work anymore.

Thank you by advance for your answers :)

Aria-dvp
5th August 2020, 14:31
The solution was simple, thanks to hskoglund on this thread [link] (https://forum.qt.io/topic/117715/deploying-a-qapplication-inside-a-dll-platform-plugin-not-found-even-if-here). Here the quote :

[...] add the path to the Qt files yourself via some C++ code, this has to be done before QApplication's constructor (because that's where the plugin loading occurs), say like this:

...
QCoreApplication::addLibraryPath("C:/Project folder");
QApplication a(argc,argv);
...

d_stranz
5th August 2020, 16:39
Can you supply any details about how you managed to get QApplication running in a DLL? A lot of people have tried this, and as far as I know you are the first to report success. It would be great if we could have a general recipe for encapsulating Qt in a DLL that runs in a non-Qt application.

Aria-dvp
7th August 2020, 14:34
Can you supply any details about how you managed to get QApplication running in a DLL? A lot of people have tried this, and as far as I know you are the first to report success. It would be great if we could have a general recipe for encapsulating Qt in a DLL that runs in a non-Qt application.

Hi d_stranz !

I didn't know at all that I was the first one. Yes I can do this, I'm thinking about doing a blog article in order to share this experience, I would be glad to help. :)
I'll be back here to share the link when it'll be done.