gpt4 book ai didi

c++ - 尝试导入 QuickControl 时出错

转载 作者:行者123 更新时间:2023-12-02 10:08:23 25 4
gpt4 key购买 nike

我想在 Ubuntu 中用 Cmake 做一个项目。

我的 CMakeList 是:

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"
)

我收到以下错误:

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

当我添加 find_package(Qt5QuickControls2 REQUIRED) 时,出现以下错误:

/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.

最佳答案

您的第二个答案为您提供了最大的线索。您(至少)缺少 QtQuickControls2 的 CMake 配置文件。在 Ubuntu 上,如果一个包提供了 CMake 配置文件(就像 Qt5 那样),它们将位于包的 -dev 版本中。确保您拥有所用 Qt5 组件的所有 -dev 包。

如果您从 apt 使用 Qt5:

$ 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

如果您通过其来源使用 Qt5,请确保您已根据其说明正确配置和安装 Qt5。

然后,使用最小的 CMakeLists.txt,例如:

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()

结果如下:

$ 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

$

如果您仍然对在 Ubuntu 上安装缺少的软件有疑问,这里有 other resources you can try .

关于c++ - 尝试导入 QuickControl 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50103959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com