QT6, Debug Version Runs, Release Version Does Not
-
I'm using Visual Studio on Windows 11 to build many QT projects, both command line and gui.
Starting a week ago, none of my gui based QT6 programs will run the released version, showing the familiar box:
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
The test program is the trivial program created with VS2022 as a QWidget program. Under 6.3.1, compiling and running as debug always works. Compiling as release never works. Under 5.15.2, they both work.
Test opens a main window and does nothing else.
main.cpp
#include "test.h"
#include <QtWidgets/QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
test w;
w.show();
return a.exec();
}test.h:
#pragma once#include <QtWidgets/QMainWindow>
#include "ui_test.h"class test : public QMainWindow
{
Q_OBJECTpublic:
test(QWidget *parent = nullptr);
~test();private:
Ui::testClass ui;
};test.cpp:
#include "test.h"test::test(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}test::~test()
{}I have Qt5.15.2, Qt6.3.1 and Qt6.4.0 installed and listed under Qt versions.
This trivial program under 5.15.2 works for both debug and release. Compiling and running under 6.3.1 works for debug and won't run as release, giving the usual "Qt platform plugin could not be initialized" message.
C:\Qt\6.3.1\msvc2019_64\plugins\platforms\qwindows.dll exists.
I burned QT to the ground and reinstalled 6.3.1 and 6.4.0.
I even reinstalled Windows 11 from a backup from few weeks ago.
The frustrating part is that gui programs compiled as release using 6.3.1 has worked in the past.
Somehow, the message must be telling me something I don't understand, so this example will probably work for you. Maybe I need to install a new Windows 11, Visual Studio 2022 and QT, but that seems extreme, and based on my experience, won't fix it anyway.
I can leave the gui programs on 5.15.2 for now, but don't want to be stuck there forever.
Any suggestions are very welcomed.
-
You need to find out more information about the error. You can use either Dependency Walker or
dumpbin /imports <exe|dll file>
.I just tested on Windows 11 with MSVC 2022 (v 17.1.32414.318) configured with Qt 6.3.1 MSVC 2019 and the release application started fine.
It might be that the
Event Viewer
Windows application has some information underWindows Logs -> Application
.As usual with Visual C++ applications, if you haven't compiled them with a static C++ runtime, you need to install the Visual C++ Runtime (2015-2022).
-
In addition to what @cristian-adam suggested, you should try setting the QT_DEBUG_PLUGINS environment variable before launching the app. Does it say it actually tries to load
C:\Qt\6.3.1\msvc2019_64\plugins\platforms\qwindows.dll
? -
I haven't tried your suggestions yet but have a bit of information.
The message sure looks like a path problem, so I added C:\Qt\6.3.1\msvc2019_64\bin; to the front of my path and programs compiled as 6.3.1started running. Somehow, the debug version was finding the directory, but not the release version.Where does the path get set for a project? I looked carefully in the .vcxproj file, but don't see it. Maybe VCTargetsPath? I have found that sometimes changing .vxcproj from within VS messes up the file.
Now I'm faced with rearranging my PATH environment variable when I change from 5.15.2 to 6.3.1 to 6.4.0.
-
@ktwolff said in QT6, Debug Version Runs, Release Version Does Not:
Somehow, the debug version was finding the directory, but not the release version.
Maybe there are no debug dlls for 6.4.0