Good day!
For me, he came out not very kind, 10 hours of life spent in search of a solution to a simple question, but ultimately I found it, and now I will share it with you.
So, a brief background.
One of my customers asked me to develop a kiosk-mode application on Qt. And for starters, make a version for a POS terminal running Windows XP.
Ok, for a week I made something on the attached layouts and tried to give the version to the customer. Having attached Qt5Core.dll, Qt5Gui.dll, well and other .dll used Qt modules.
"Failed to load platform plugin" windows "," said a
Japanese Finnish chainsaw.
Yeah, go to google.
First, the official documentation:
qt-project.org/doc/qt-5.0/qtdoc/deployment-windows.htmlShe didn’t help much, went to read the forums on qt-project.org. Here are the proposed solutions:
1) copy /qtbase/plugins/platforms/qwindows.dll to the application folder in the platforms or platform directory
tried it does not work
2) copy /qtbase/plugins/platforms/qwindows.dll to the application folder in the plugins / platforms, plugins / platform directory
does not work
3) set the QT_QPA_PLATFORM_PLUGIN_PATH environment variable, specify the path to the qwindows.dll folder in it
earned. But: I do not want to modify the environment variables when installed on the user's computer. First, the user can remove it - and since the application crashes when loading, I cannot even check its presence without crutches. Secondly, the user can install the application with a different version of Qt - and hello, glitches and incompatibilities.
4) the decision of the official documentation. When initializing an application in the main () function, add a line like:
qApp->addLibraryPath("C:/customPath/plugins");
qApp is our QApplication. It did not work.
5) use the command line argument "-platformpluginpath \" path_to_folder_c_qwindows.dll \ ""
checked works. Voila! Here is the solution! (which was not true)
Edit the innosetup script, like this:
[Files] ... Source: "..\build\deploy\platforms\qwindows.dll"; DestDir: "{app}\platforms"; Flags: ignoreversion [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\TryumPosWin.exe"; Parameters:"-platformpluginpath \"{app}\platforms\"" ; WorkingDir: "{app}";
')
We give to the customer, rejoice.
Early rejoice, sqlite does not work. laying in plugins \ sqldrivers, just sqldrivers did not help - does not see and does not load, here is the code:
if (QSqlDatabase::isDriverAvailable("QSQLITE")){ qDebug("QSqlite driver found."); } else { qFatal("QSqlite driver NOT found!"); }
dropped out with an error. I did not find either the environment variable or the command line argument for the sql plug-ins.
Returned to the official documentation and thought. And actually why do we call a static method from an instance?
And since it is static, can it be called before creating an instance?
This code finally works:
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(resources); QStringList paths = QCoreApplication::libraryPaths(); paths.append("."); paths.append("imageformats"); paths.append("platforms"); paths.append("sqldrivers"); QCoreApplication::setLibraryPaths(paths); QApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); QDbc::init(); MainWindow w; w.showFullScreen(); a.exec(); QDbc::finalize(); }
By the way, I also met this way of setting the path:
paths.append(QCoreApplication::applicationDirPath() + "/plugins");
but it does not work correctly, since QCoreApplication :: applicationDirPath () returns a warning if the QApplication instance has not yet been created.
And the actual “Files” section in InnoSetup looks like this:
[Files] Source: "..\build\deploy\icudt51.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\icuin51.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\icuuc51.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\libEGL.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\libGLESv2.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\msvcp100.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\msvcr100.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\Qt5Core.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\Qt5Gui.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\Qt5Network.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\Qt5Sql.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\Qt5Widgets.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "..\build\deploy\imageformats\qico.dll"; DestDir: "{app}\imageformats"; Flags: ignoreversion Source: "..\build\deploy\platforms\qwindows.dll"; DestDir: "{app}\platforms"; Flags: ignoreversion Source: "..\build\deploy\sqldrivers\qsqlite.dll"; DestDir: "{app}\sqldrivers"; Flags: ignoreversion
The article does not claim to be a comprehensive study, but I did not find a working solution, and therefore I decided to publish my own.
Thanks for attention!