Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to import QuickControls

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.

like image 446
amir sharifi Avatar asked Sep 02 '26 05:09

amir sharifi


1 Answers

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 qtquickcontrols2-5-dev   ## provides QuickControls2

If you're using Qt5 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.

like image 145
nega Avatar answered Sep 04 '26 19:09

nega



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!