Cannot find the Qt platform plugin after migrating to Qt 6
-
I am migrating my project from Qt 5 to Qt6.
The project builds and runs successfully outside Qt Creator. I do have to run windeployqt before I can run the application. For this I have created a batch file that creates a build directory, runs CMake, builds the project, runs windeployqt, and copies some files manually (libmysql* and libssl*).
Now I am trying to get the project to work in Qt Creator. It builds successfully, but when trying to run (debug) it, it fails because the platform plugin cannot be found:
qt.qpa.plugin: Could not find the Qt platform plugin "windows" in "" This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Debug Error! Program: ...\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Debug\src\Qt6Cored.dll Module: 6.8.1 File: C:\src\vcpkg\buildtrees\qtbase\src\here-src-6-9f6e91ffa0.clean\src\gui\kernel\qguiapplication.cpp Line: 1327 This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
This problem did not occur when I was still using Qt 5.
Could this be caused by Qt Creator mixing different instances of Qt? I am using vcpkg for building the dependencies of my project (taglib and Qt), but I also had to install Qt with the Maintenance Tool so a kit could be created in Qt Creator. Both Qt instances are version 6.8.1.
To open the project in Qt Creator and get it to build I did the following:
- Open the CMakeLists.txt file (fails to configure automatically)
- Switch the kit to a Qt 6 kit (somehow a Qt 5 kit was still selected; configure fails again after switching)
- Add CMake variable VCPKG_TARGET_TRIPLET with value x64-windows
- Add CMake variable CMAKE_TOOLCHAIN_FILE and point it to C:\src\vcpkg\scripts\buildsystems\vcpkg.cmake
- Reconfigure with initial parameters
- Build
So the projects builds successfully but refuses to run because of the missing platform plugin. I looked into adding a deploy step when running, but windeployqt or installing plugins isn't one of the options. And isn't Qt Creator supposed to take care of the plugins automatically anyway?
The vcpkg plugin in Qt Creator is enabled, although I have no idea how to use it or what it is supposed to do. Back when I was still using Qt 5 I was using Qt Creator without that plugin.