2
votes

I'm trying to start writing my Qt project inside JetBrains' Clion but I need to link some libraries in my Cmake file first. There's no problem when trying to find packages like Qt5Core, Qt5Widgets, Qt5Gui but when it come to finding Qt5Charts an error is thrown:

By not providing "FindQt5Charts.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt5Charts", but CMake did not find one.

Could not find a package configuration file provided by "Qt5Charts" with any of the following names:

Qt5ChartsConfig.cmake
qt5charts-config.cmake

Add the installation prefix of "Qt5Charts" to CMAKE_PREFIX_PATH or set "Qt5Charts_DIR" to a directory containing one of the above files. If "Qt5Charts" provides a separate development package or SDK, be sure it has been installed.

This is my CMake file right now.

All packages are installed via the Qt's Linux(ubuntu) maintanence tool. Any ideas how to help Cmake find the Charts module ?

2
Some Qt 5.x versions had problems with including QtCharts, and one of the keywords to solve was QT_CHARTS_USE_NAMESPACE...Vladimir Bershov
@Vladimir Bershov Where do you type those keywords? In the Cmake?user7973129
Did you add QT += charts to your .pro file ?Vladimir Bershov
@VladimirBershov yes I did.user7973129

2 Answers

2
votes

Using the following and see if it helps:

sudo apt install libqt5charts5-dev

Src: https://stackoverflow.com/a/46765025

0
votes

Typically when including Qt5 in a project I use the follow basic script for CMake, though I should note I haven't tested this on Linux.

cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
project(<YOUR_PROJECT_NAME>)

find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Charts)

# set your project sources and headers
set(project_sources src/blah.cpp)
set(project_headers include/headers/blah.h)

# wrap your qt based classes with qmoc
qt5_wrap_cpp(project_source_moc ${project_headers})

# add your build target
add_executable(${PROJECT_NAME} ${project_sources} ${project_headers} ${project_source_moc})

# link to Qt5
target_link_libraries(${PROJECT_NAME}
    PUBLIC
    Qt5::Core
    Qt5::Gui
    Qt5::Widgets
    Qt5::Charts)

# require C++ 14
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)

When configuring your project via cmake, you just need to pass in the path to you qt5 installation directory (cmake variable name is Qt5_DIR) that contains the Qt5Config.cmake file and then cmake should be able to find the rest of the components that you request.

Also double check that Qt5Charts was installed, not sure if it's installed by default.