Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Qt5 installed via VCPKG in Visual Studio for C++

I know this is a daft question, but I'm a beginner in visual studio/c++/cmake. I'm looking for a quick intro on how to use Qt5 installed via vcpk using:

vcpkg install qt5-base:x64-windows

This all installed ok and I got the following:

The package qt5-base:x64-windows provides CMake targets:

find_package(Qt5Concurrent CONFIG REQUIRED)
target_link_libraries(main PRIVATE Qt5::Concurrent Qt5::ConcurrentPrivate)

etc....

I just don't know what to do next! Before using libs in VS I just did an <#include> now I'm confronted with this lot... Pref. I want some sort of explanation at newbie level please.

If I add the line (at the top of a .cpp file just as a test):

#include <QtWidgets/QApplication>

It gives: Error (active) E1696 cannot open source file "QtWidgets/QApplication"

I'm new, I thought vcpkg took all the pain out of having to add all the libs etc to the project options? What do I need to do?


1 Answers

If you ran vcpkg integrate install and are just using VS you can just #include <Qt5/QtWidgets/QApplication>

If you are using CMake: find_package(Qt5 COMPONENTS Widgets Concurrent CONFIG REQUIRED) and use target_link_libraries as described by the other answers. But you probably have to switch to #include <QApplication> since cmake file add the QtWidgets folder to the include folders.

For find_package to find the vcpkg build versions you have to specify the vcpkg.cmake toolchain file as the CMAKE_TOOLCHAIN_FILE=<vcpkgroot>/scripts/buildsystems/vcpkg.cmake (must be set in the first CMake call or rather early in the CMakeLists.txt before any project() call) and maybe also VCPKG_TARGET_TRIPLET=<sometriplet> (must also be defined early before CMAKE_TOOLCHAIN_FILE is loaded) if you installed Qt5 using one of the static triplets.

like image 173
Alexander Neumann Avatar answered Sep 10 '25 06:09

Alexander Neumann