Deploy on Windows

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?

@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.

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.

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 weird

Do 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?

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.)

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 bug

It'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:

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...

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 :-)

@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 much