I am trying to install Qt6 using vcpkg, and use it in a Visual Studio 2019 CMake project. I have tried linking other libraries (ex: fmt) and it worked. However, when I add Qt in the mix, building succeeds, but running the executable fails:
the popup shows:
Program ... QtCored.dll
...
This application failed to start because no Qt platform could be initialized
...
and the console says
qt.qpa.plugin: Could not find the Qt platform plugin "windows" in "C:\vcpkg\installed\x64-windows\Qt6\plugins\platforms"
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Environment variables: I set VCPKG_ROOT to C:\vcpkg, QT_PLUGIN_PATH to C:\vcpkg\installed\x64-windows\Qt6\plugins\platforms, QT_QPA_PLATFORM_PLUGIN_PATH to C:\vcpkg\installed\x64-windows\Qt6\plugins\platforms, added C:\vcpkg\installed\x64-windows\Qt6 and C:\vcpkg to the path.
I tried putting the exe in a separate folder, and running windeployqt.exe on it, but it fails as well...
windeployqt.exe C:\Users\broland\Desktop\NewFolder\HelloWorld.exe
Warning: Translations will not be available due to the following error.
Cannot open C:/vcpkg/installed/x64-windows/translations/Qt6/catalogs.json
Unable to find dependent libraries of C:\vcpkg\installed\x64-windows\bin\Qt6Widgetsd.dll :Cannot open 'C:/vcpkg/installed/x64-windows/bin/Qt6Widgetsd.dll': The system cannot find the file specified.
My CMakeLists.txt:
cmake_minimum_required (VERSION 3.8)
set(CMAKE_AUTOMOC ON) # https://stackoverflow.com/questions/14170770/unresolved-external-symbol-public-virtual-struct-qmetaobject-const-thiscal
set(CMAKE_INCLUDE_CURRENT_DIR ON) # so that mainwindow.h and mainwindow.cpp is seen
project (HelloWorld)
find_package(fmt CONFIG REQUIRED)
find_package(Qt6Core REQUIRED)
find_package(Qt6Gui CONFIG REQUIRED)
find_package(Qt6Widgets REQUIRED)
add_executable (HelloWorld "helloworld.cpp" "helloworld.h" "mainwindow.cpp")
#add_executable (HelloWorld "mainwindow.cpp" "mainwindow.h" "mainwindow.cpp")
target_link_libraries(HelloWorld PRIVATE fmt::fmt)
target_link_libraries(HelloWorld PRIVATE Qt::Gui)
target_link_libraries(HelloWorld PRIVATE Qt::Core)
target_link_libraries(HelloWorld PRIVATE Qt::Widgets)
Been trying for days. Any suggestions?
So, instead of using vcpkg, I installed Qt through the online installer.
For anyone else struggling, I will leave this here. I followed parts of this and this tutorials.
Since I use Visual Studio, I downloaded the
MSVC 2019 64-bitversion. I set the environment variableQTDIRequal to the path wheremsvc2019_64folder lies. I added to thePathenv. var.%QTDIR%\liband%QTDIR%\bin. To check if I can link othervcpkginstalled libraries, I gotOpenCV(vcpkg install opencv). It seems to work. The path inINCLUDEis where I have the respective file, ip, ua and var are folders of my project containing source and header files.My CMakeLists.txt: