#include <qtwidgets>在使用ros kinetic ubuntu 16.06的Qt 5.5中无效

时间:2017-06-08 10:37:47

标签: c++ qt ubuntu qt5

我有一个ros项目,在ubuntu 14.04下在ros-indigo下构建得很好 现在我切换到ros-kinetic和ubuntu 16.04,我在构建代码时遇到以下错误:

  

错误&lt;&lt; rviz_satellite:使   /home/kohaf3/opel_ws/logs/rviz_satellite/build.make.028.log In   文件包括   /home/kohaf3/opel_ws/build/rviz_satellite/src/moc_aerialmap_display.cpp:9:0:   /home/kohaf3/opel_ws/build/rviz_satellite/src/../../../src/rviz_satellite/src/aerialmap_display.h:43:21:   致命错误:QtWidgets:没有这样的文件或目录编译   终止。 make [2]: *   [CMakeFiles / rviz_satellite.dir / src / moc_aerialmap_display.cpp.o]错误   1 make [2]: 等待未完成的工作....在包含的文件中   /home/kohaf3/opel_ws/src/rviz_satellite/src/aerialmap_display.cpp:45:0:   /home/kohaf3/opel_ws/src/rviz_satellite/src/aerialmap_display.h:43:21:   致命错误:QtWidgets:没有这样的文件或目录编译   终止。 make [2]:   [CMakeFiles / rviz_satellite.dir / src / aerialmap_display.cpp.o]错误1   make [1]:* [CMakeFiles / rviz_satellite.dir / all]错误2 make:***   [全部]错误2

我的CMakeLists文件如下:

cmake_minimum_required(VERSION 2.8.3)
project(rviz_satellite)

set(DISTRO $ENV{ROS_DISTRO})
message("Distribution: " ${DISTRO})

set(DEFAULT_BUILD_QT5 OFF)
if(${DISTRO} STREQUAL "kinetic")
    set(DEFAULT_BUILD_QT5 ON)
endif()

option(UseQt5 "Build w/ QT version 5" ${DEFAULT_BUILD_QT5})

if (UseQt5)
    find_package(Qt5 COMPONENTS Core Gui Network Concurrent REQUIRED)
        message("qt5 is used")
else()
    find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED)
    include(${QT_USE_FILE})
        message("qt4 is used")
endif()

find_package(OpenCV REQUIRED)
find_package(PkgConfig REQUIRED)

pkg_check_modules(OGRE_OV OGRE OGRE-Overlay)

# Old versions of OGRE (pre 1.9) included OGRE-Overlay in the main package
# (i.e. there was no OGRE-Overlay component).  So if the above
# pkg_check_modules() failed, try looking for just OGRE.
if(NOT OGRE_OV_FOUND)
  pkg_check_modules(OGRE_OV REQUIRED OGRE)
endif()

find_package(catkin REQUIRED COMPONENTS
  nav_msgs
  roscpp
  rviz
  sensor_msgs
  geodesy
  rtkrcv_ros_tool# wichtig für include:#include <rtkrcv_ros_tool/GPS_rtklib.h>
)

#generate_messages(
 # DEPENDENCIES
 # std_msgs
#)

catkin_package(CATKIN_DEPENDS nav_msgs sensor_msgs )#message_runtime)



set(${PROJECT_NAME}_SOURCES
  src/aerialmap_display.cpp
  src/tileloader.cpp
  src/rviz_plot_markers.cpp
)

set(${PROJECT_NAME}_HEADERS
  src/aerialmap_display.h
  src/tileloader.h
)

# invoke MOC and UI/ include Qt headers/ link Qt libraries
if (UseQt5)
    qt5_wrap_cpp(${PROJECT_NAME}_MOCSrcs ${${PROJECT_NAME}_HEADERS})
    include_directories(
        ${Qt5Core_INCLUDE_DIRS}
        ${Qt5Gui_INCLUDE_DIRS}
        ${Qt5Network_INCLUDE_DIRS}
        ${Qt5Concurrent_INCLUDE_DIRS}
                "/usr/include/qt5"
        )
    link_libraries(
        ${Qt5Core_LIBRARIES}
        ${Qt5Gui_LIBRARIES}
        ${Qt5Network_LIBRARIES}
        ${Qt5Concurrent_LIBRARIES}
        )
else()
    qt4_wrap_cpp(${PROJECT_NAME}_MOCSrcs ${${PROJECT_NAME}_HEADERS})
    include_directories(${Qt4_INCLUDE_DIR})
    link_libraries(
        ${QT_LIBRARIES}
        )
endif()

# Other includes
include_directories(
  ${CMAKE_CURRENT_BINARY_DIR}
  ${OpenCV_INCLUDE_DIR}
  ${OGRE_OV_INCLUDE_DIRS}
  ${catkin_INCLUDE_DIRS}
  src
)

# Other libraries
link_libraries(
  ${QT_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${catkin_LIBRARIES}
)

add_definitions("-Wall -Wunused -std=c++11")

set(PROJECT_SOURCE_FILES
  ${${PROJECT_NAME}_SOURCES}
  ${${PROJECT_NAME}_MOCSrcs}
)

add_library(${PROJECT_NAME}
  ${PROJECT_SOURCE_FILES}
)

install(TARGETS ${PROJECT_NAME}
    RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
    ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
    LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)

install(FILES plugin_description.xml DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

# von Markus:
add_executable(rviz_node
    src/rviz_plot_markers.cpp)
add_dependencies(rviz_node ${catkin_EXPORTED_TARGETS})
target_link_libraries(rviz_node
  ${catkin_LIBRARIES}
)

qmake --version

QMake version 3.0
Using Qt version 5.5.1 in /usr/lib/x86_64-linux-gnu

pkg-config --modversion QtCore

4.8.7

qtdiag

Library info:   PrefixPath: /usr   DocumentationPath: /usr/share/qt5/doc  
HeadersPath: /usr/include/x86_64-linux-gnu/qt5   LibrariesPath: /usr/lib
/x86_64-linux-gnu   LibraryExecutablesPath: /usr/lib/x86_64-linux-gnu/qt5
/libexec   BinariesPath: /usr/lib/x86_64-linux-gnu/qt5/bin   PluginsPath: 
/usr/lib/x86_64-linux-gnu/qt5/plugins   ImportsPath: /usr/lib/x86_64-
linux-gnu/qt5/imports   Qml2ImportsPath: /usr/lib/x86_64-linux-gnu/qt5/qml
ArchDataPath: /usr/lib/x86_64-linux-gnu/qt5   DataPath: /usr/share/qt5   
TranslationsPath: /usr/share/qt5/translations   ExamplesPath: /usr/lib
/x86_64-linux-gnu/qt5/examples   TestsPath: /usr/tests   
SettingsPath: /etc/xdg

我还安装了Qt creator ros插件,请看这里(https://github.com/ros-industrial/ros_qtc_plugin/wiki/1.-How-to-Install-(Users)

2 个答案:

答案 0 :(得分:1)

这对我来说很有用:

if (UseQt5)
        find_package(Qt5 COMPONENTS Core Gui Network Widgets Concurrent REQUIRED)
        message("qt5 is used")
        # Find Qt5Core and Qt5Widgets
        find_package(Qt5Core REQUIRED)
        find_package(Qt5Widgets REQUIRED)
        # For finding Qt includes
        include_directories(${CMAKE_CURRENT_SOURCE_DIR})
        include_directories(${Qt5Widgets_INCLUDE_DIRS})
        include_directories(${Qt5Core_INCLUDE_DIRS})

else()
        find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork QtWidgets REQUIRED)
    include(${QT_USE_FILE})
        message("qt4 is used")
endif()

答案 1 :(得分:0)

我认为你还必须在你的CMake中包含Qt的Widgets / QtWidgets模块:

if (UseQt5)
    find_package(Qt5 COMPONENTS Core Gui Network Concurrent Widgets REQUIRED)
        message("qt5 is used")
else()
    find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork QtWidgets REQUIRED)
    include(${QT_USE_FILE})
        message("qt4 is used")
endif()