2

I want to make a project with Cmake in Ubuntu.

My CMakeList is:

cmake_minimum_required(VERSION 2.8.3)
project(client_ros)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  qt_build
)

file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 
FOLLOW_SYMLINKS src/*.cpp include/client_ros/*.hpp 
include/client_ros/*.h)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}             
resources/*.qrc)
include_directories(include ${catkin_INCLUDE_DIRS})
#################################
find_package(Qt5Core REQUIRED)
find_package(Qt5Sql REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Multimedia REQUIRED)


find_package(Qt5Qml REQUIRED)


set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

#set configs
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)

QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})
include_directories(
    ${Qt5Core_INCLUDE_DIRS}
    ${Qt5Gui_INCLUDE_DIRS}
    ${Qt5Quick_INCLUDE_DIRS}
    ${Qt5QuickControls2_INCLUDE_DIRS}
    ${Qt5Widgets_INCLUDE_DIRS}
    ${Qt5PrintSupport_INCLUDE_DIRS}
    ${Qt5Qml_INCLUDE_DIRS}
   # ./src
    ${Qt5Sql_INCLUDE_DIRS}
    ${Qt5Charts_INCLUDE_DIRS}
    ${Qt5Multimedia_INCLUDE_DIRS}
    ${QT_INCLUDE_DIR}
    )

add_definitions( -std=c++11 -fPIC)
add_definitions(${Qt5Widgets_DEFINITIONS} ${QtQml_DEFINITIONS} 
${${Qt5Quick_DEFINITIONS}})

catkin_package(
 INCLUDE_DIRS
  include
  CATKIN_DEPENDS
  std_msgs
  roscpp

)
include_directories(include)
include_directories(${catkin_INCLUDE_DIRS})
include_directories(${Eigen_INCLUDE_DIRS})


add_executable(client_ros_node src/client_ros_node.cpp
src/clientclass.cpp
include/client_ros/clientclass.h
    ${coreheaders}
    ${corecpps}
)
#qt5_use_modules(gui Quick Core)
add_library(${PROJECT_NAME}

    ${QT_SOURCES}
    ${QT_MOC_HPP}
    ${QT_RESOURCES_CPP}
    ${QT_MOC}
    ${QT_UI_H}
    )
    target_link_libraries(client_ros_node ${catkin_LIBRARIES})
    target_link_libraries(client_ros_node
        Qt5::Core
        Qt5::Widgets
        Qt5::Quick
        Qt5::Sql
        Qt5::Multimedia
        )
add_dependencies(client_ros_node 
client_ros_generate_messages_cpp_qt_build)




qt5_add_resources(qml_QRC resources/qml.qrc)
qt5_use_modules(client_ros_node Quick Gui Core Widgets)

## Mark cpp header files for installation
install(DIRECTORY include/client_ros/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
)

I get the following error:

QQmlApplicationEngine failed to load component file:///home/amir/work_space/build/client_ros/devel/lib/client_ros/main.qml:1 module "QtQuick" version 2.9 is not installed

when i add find_package(Qt5QuickControls2 REQUIRED), I get the following error:

/home/amir/work_space/src/client_ros/CMakeLists.txt:19: error: By not providing "FindQt5QuickControls2.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt5QuickControls2", but CMake did not find one. Could not find a package configuration file provided by "Qt5QuickControls2" with any of the following names: Qt5QuickControls2Config.cmake qt5quickcontrols2-config.cmake Add the installation prefix of "Qt5QuickControls2" to CMAKE_PREFIX_PATH or set "Qt5QuickControls2_DIR" to a directory containing one of the above files. If "Qt5QuickControls2" provides a separate development package or SDK, be sure it has been installed.

Max Vollmer
  • 8,412
  • 9
  • 28
  • 43
amir sharifi
  • 31
  • 1
  • 4

1 Answers1

7

Your second answer gives you your biggest clue. You're missing (at a minimum) the CMake config files for QtQuickControls2. On Ubuntu if a package provides CMake config files (like Qt5 does) they'll be in the -dev version of the package. Ensure that you have all the -dev packages for the Qt5 components you're using.

If you're using Qt5 from apt:

$ sudo apt-get install qtbase5-dev              ## provides Core, Sql and Widgets
$ sudo apt-get install qtdeclarative5-dev       ## provides Quick and Qml
$ sudo apt-get install qtmultimedia5-dev        ## provides Multimedia
$ sudo apt-get install qt-quickcontrols2-5-dev  ## provides QuickControls2

If you're using Qt5 from via its sources, make sure that you've configured and installed Qt5 correctly according to its instructions.

Then, using a minimal CMakeLists.txt like:

cmake_minimum_required(VERSION 2.8)

find_package(Qt5Core REQUIRED)
find_package(Qt5Sql REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Multimedia REQUIRED)
find_package(Qt5Qml REQUIRED)

foreach(c Core Sql Widgets Quick Multimedia Qml)
    if(${Qt5${c}_FOUND})
        message(STATUS "Qt5${c} found!")
    endif()
endforeach()

results in the following:

$ cmake .           
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Qt5Core found!
-- Qt5Sql found!
-- Qt5Widgets found!
-- Qt5Quick found!
-- Qt5Multimedia found!
-- Qt5Qml found!
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nega/qt

$

If you still have questions about installing missing software on Ubuntu, there are other resources you can try.

nega
  • 2,526
  • 20
  • 25
  • According to what I see is not using the library that provides ubuntu or similar, but has downloaded Qt directly, your answer does not help in that case, also could cause compatibility problems. – eyllanesc Apr 30 '18 at 18:28
  • @eyllanesc Obviously you missed "If you're using Qt5 from via its sources, make sure that you've configured and installed Qt5 correctly according to its instructions." Qt5 has excellent documentation, and properly installed CMake can easily discover it. You'll also notice that the base of Qt5 is properly installed otherwise an error would have been generated before the error for Qt5Quick. The point is that Quick (the first error) QuickControls2 (the second error) _are not_ properly installed. And, that needs to happen via `apt` or via source. – nega Apr 30 '18 at 18:39
  • The version that provides ubuntu via apt-get is not Qt 5.10 as pointed out by the asker, the Qt documentation is one of the best but how to know that the asker has configured it correctly, the installer has downloaded the latest version, this installation it is portable so the paths are not established. – eyllanesc Apr 30 '18 at 18:48
  • True, as of Ubuntu 18.04, Ubuntu provides 5.9.5. But, @amirsharifi hadn't replied when I wrote my answer. :) Indeed, how do we know Qt5 is installed correctly? Well, the base has been installed correctly. Qt modules that rely on the base are smart enough to install themselves along side. Anyway comments are not for discussion. If you have a comment that will help to improve my answer, feel free to add one. Otherwise take it to talk. – nega Apr 30 '18 at 18:59
  • hahaha, no, that is not true, the asker could have installed it incorrectly, you will find innumerable questions caused by a bad installation. – eyllanesc Apr 30 '18 at 19:01
  • CMake would have failed at `find_package(Qt5Core REQUIRED)` if it was installed incorrectly. – nega Apr 30 '18 at 19:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170108/discussion-between-nega-and-eyllanesc). – nega Apr 30 '18 at 19:05
  • And if it is pointing to the Qt that ubuntu provides, then it will not mark the error. But it will mark the error in the QtQuick since the version that the import is very new, so there are 2 possible solutions: use `import QtQuick 2.7` or correct that the path points to the version Qt 5.10.1. – eyllanesc Apr 30 '18 at 19:07