Deploy on Windows
-
Hello everyone.
I I know that this is the most boring question that there is but I can not get out.
- Windows 10 platform (same problem on Windows 7)
- QT 5.5.1
- Visual Studio 2013
I create a base project (one blank form) so I compile in release.
Within the directory where the executable is generated and launch "windeployqt.exe." everything is successful and the application starts without problems.Doing the same exact steps on the project I'm working on for some time (I started the development of a previous version of QT) the result however is an error "This application failed to start because it could not find or load the QT "windows" platform plugin."
Of course, by launching the application inside QtCreator it works.
What hell could be the cause?Paste under the project file contents:
#------------------------------------------------- # # Project created by QtCreator 2016-03-30T14:47:01 # #------------------------------------------------- QT += sql core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport TARGET = AnalisiQT TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ qcustomplot.cpp \ qcpdocumentobject.cpp HEADERS += mainwindow.h \ qcustomplot.h \ qcpdocumentobject.h FORMS += mainwindow.ui
The tree
C:. │ AnalisiQT.exe │ D3Dcompiler_47.dll │ libEGL.dll │ libGLESV2.dll │ main.obj │ mainwindow.obj │ moc_mainwindow.cpp │ moc_mainwindow.obj │ moc_qcpdocumentobject.cpp │ moc_qcpdocumentobject.obj │ moc_qcustomplot.cpp │ moc_qcustomplot.obj │ opengl32sw.dll │ qcpdocumentobject.obj │ qcustomplot.obj │ Qt5Core.dll │ Qt5Gui.dll │ Qt5PrintSupport.dll │ Qt5Sql.dll │ Qt5Svg.dll │ Qt5Widgets.dll │ ├───iconengines │ qsvgicon.dll │ ├───imageformats │ qdds.dll │ qgif.dll │ qicns.dll │ qico.dll │ qjp2.dll │ qjpeg.dll │ qmng.dll │ qsvg.dll │ qtga.dll │ qtiff.dll │ qwbmp.dll │ qwebp.dll │ ├───platforms │ qwindows.dll │ ├───printsupport │ windowsprintersupport.dll │ ├───sqldrivers │ qsqlite.dll │ qsqlmysql.dll │ qsqlodbc.dll │ qsqlpsql.dll │ └───translations qt_ca.qm qt_cs.qm qt_de.qm qt_en.qm qt_fi.qm qt_fr.qm qt_he.qm qt_hu.qm qt_it.qm qt_ja.qm qt_ko.qm qt_lv.qm qt_ru.qm qt_sk.qm qt_uk.qm
Thank you in advance
-
Not a solution but I'm wondering why you have *obj and *.cpp files there?
-
Hi,
Since you wrote that you have used an older version of Qt for that project, did you clean the shadow build directory before running windeployqt ?
-
Hi @SGaist.
I completely deleted the build directory.
Compiled , object files deleted.
Windeployqt performed but the result does not change , still the same error.This new clean tree :
C:\Users\ME\Documents\ProgettiQT\AnalisiQT\build-AnalisiQT-Desktop_Qt_5_5_1_MSVC2013_64bit-Release\release>tree /F Elenco del percorso delle cartelle Numero di serie del volume: DA56-7BF2 C:. │ AnalisiQT.exe │ D3Dcompiler_47.dll │ libEGL.dll │ libGLESV2.dll │ opengl32sw.dll │ Qt5Core.dll │ Qt5Gui.dll │ Qt5PrintSupport.dll │ Qt5Sql.dll │ Qt5Svg.dll │ Qt5Widgets.dll │ ├───iconengines │ qsvgicon.dll │ ├───imageformats │ qdds.dll │ qgif.dll │ qicns.dll │ qico.dll │ qjp2.dll │ qjpeg.dll │ qmng.dll │ qsvg.dll │ qtga.dll │ qtiff.dll │ qwbmp.dll │ qwebp.dll │ ├───platforms │ qwindows.dll │ ├───printsupport │ windowsprintersupport.dll │ ├───sqldrivers │ qsqlite.dll │ qsqlmysql.dll │ qsqlodbc.dll │ qsqlpsql.dll │ └───translations qt_ca.qm qt_cs.qm qt_de.qm qt_en.qm qt_fi.qm qt_fr.qm qt_he.qm qt_hu.qm qt_it.qm qt_ja.qm qt_ko.qm qt_lv.qm qt_ru.qm qt_sk.qm qt_uk.qm
-
How are you starting the application after your ran windeployqt ? From explorer ? The command line ?
-
@SGaist
I do not understand why but copying Qt5Core.dl from C: \ Qt \ Qt5.5.1 \ 5.5 \ msvc2013_64 \ bin and overwriting the previously written by windeployqt.exe the application now starts from both explorer and command line .
I'll try to move the application on a machine that does not have Qt but I have serious doubts that it works.
For me it is still incomprehensible and I'd like to understand. -
Do you have several versions of Qt installed ?
-
Hi, about why replacing back the Qt5Core.dll from C:\Qt\Qt5.5.1\msvc2013_64\bin directory makes your app work again:
starting with Qt5.5 this change in windeployqt patches Qt5Core.dll so it clears the "pathological connection" it has to your installation directory. In other words, if after doing windeployqt, your .exe file launches ok, then you can be sure it also runs ok on another PC without Qt installed.
But in your case it does not :-(So either windeployqt does not copy everything for the Windows platform plugin (qwindows.dll) to start ok, or perhaps, as @SGaist suggests above, you have multiple versions of Qt and windeployqt copies the wrong qwindows.dll.
You could check what is different, when starting your app from Qt Creator and after windeployqt, download Process Explorer select your AnalisiQt.exe, select View, Show Lower Pane, Lower Pane View: DLLs, and then compare the lists.
-
Hi @hskoglund
Thanks for the info and for the analysis program.
I have only one version of QT installed.
Analyzing the application while running, after copying the dll, I see that it uses C:\Qt\Qt5.5.1\5.5\msvc2013_64\plugins\platforms\qwindows.dll instead of dll that windeployqt copied in my application folder.
Even for qsqlodbc.dll is used this C:\Qt\Qt5.5.1\5.5\msvc2013_64\plugins\sqldrivers\qsqlodbc.dll rather than copied by windeploywt
If I leave the dll that has copied windeployqt the application fails to open qwindows.dll
Really weirdDo you think that a static compilation could be the solution?
Can you recommend a tutorial for static compilation?
But above all , can I build statically if I'm using the open version of QT?Thank you very much for helping
-
Hi, getting Qt's plugins to load nicely: I write about in my blog As you can see, there are at least 5 ways in which Qt tries to find them. And the first one is that hardwired "prfxpath=C:\Qt\Qt5.5.1\5.5\msvc2013_64" in Qt5Core.dll which windeployqt changes to "prfxpath=."
(My blog is a bit outdated, qt_plugpath is gone in 5.5)What you can try, is to adjust for a slight bit of stupidness from windeployqt, it copies all the plugin dll directories directly into your directory (...\iconengines, ...\imageformats, ...\platforms, etc.) but then sets prfxpath to "." in Qt5core.dll, which tells Qt to look for the platform dlls in ....\plugins\iconengines, ...\plugins\imageformats, ...\plugins\platforms etc.)
Indeed, that's a mismatch of directory specs, one that usually doesn't matter, because Qt (as I write in my blog) also tries to load the plugins DLLs from the directory where your .exe file is (the current directory). But in same cases it does matter, for example, in your main() in main.cpp, do you do anything fancy before
QApplication a(argc, argv);
?Anyway, in your directory with your .exe file, try to create another subdirectory called plugins, and move all the other subdirectories into it, then try again to launch your app.
(And about static compilation: I think it's too much of a hassle when developing your app, but later once your app is stable ('frozen") then the extra time for static compilation is justified I think.)
-
Hi @hskoglund
Thank you very much for the help.
With the information you have given me I solved but above all through the article on your blog I understood
Let's say that my goal was really to understand.I took all of the plugins folders generated by windeployqt and I moved to a new folder named "plugins".
Now, if the problem occurs again on another project, I know several ways to deal with it and different ways to solve it.
Thank you
-
Hi, good!
Problem was I couldn't stop wondering why you got this problem in the first place... lots of coffee later, I think I know:
you got bitten by this bugIt's a quite interesting bug :-) Anyway I thought it was fixed for Qt 5.5.1 but it turns out it was fixed for 5.6, so if you upgrade your Qt installation to 5.6, then you should not need to add that plugins directory anymore.
If you're curious like me, you might wonder how you triggered that bug? The simplest way to recreate the bug is to first create a vanilla widgets projects (like my HelloQt projects in my blog) and then insert a single line before constructing the QApplication in main.cpp. Like this:
int main(int argc, char *argv[]) { QApplication::libraryPaths(); QApplication a(argc, argv); ...
Anyway, that bug is gone in 5.6. But also I realized that the "slight bit of stupidness" from windeployqt could be considered a bug, because there might still be other use cases when doing something before constructing QApplication() will fail...
-
Hi @hskoglund
In my case the cause should be the one that I paste below (unless I've made some other test that I can not remember)#include "mainwindow.h" #include <QApplication> #include <qsqldatabase.h> #include <qsqlquery.h> #include <QtDebug> // The guilty QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); bool dbok; int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
-
Aha, I see, thanks for responding!
Yes that ::addDatabase() will try to load the qsqlodbc.dll plugin before constructing the QApplication (and Qt is kind of confused before there's a QApplication).
If you upgrade to Qt 5.6 and try that code I think you should see a warning "please construct a QApplication first" or something like that. So it's worth upgrading just to get better error messages :-) -
There really is no need for a static QSqlDatabase object.
Take a look at the QSqlDatabase detailed documentation. There's a nice description on how to use it.
Beside eliminating your current problem and since you seem to only have one database connection, you'll likely be able to simplify your code.
-
Now I have changed my code, the application works correctly but I still have to put the plugin in the plugins folder.
#include "mainwindow.h" #include <QApplication> int main (int argc, char * argv []) { QApplication a (argc, argv); MainWindow w; w.show (); return a.exec (); }
@hskoglund I can not use QT 5.6.0 because it has problems with ODBC that should be solved with the next version.
@SGaist I read the documentation that you suggested, thanks for the links
I love the community such as QT and Linux ones, they have helped me to understand and learn, I am convinced that they are one of the most powerful means available to us, especially because in the world there are people like you that help and explain .
Thanks so muchSorry for my bad English