ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Unable to build Qt5 Application with custom ROS messages

asked 2019-02-04 00:40:27 -0500

goparakeets21 gravatar image

I'm attempting to add a custom ROS message to a simple QT5 application. I placed 3 files into msg folder in the package root, called generate on them and verified that they were built in my devel directory. It seems once catkin trys to build the QT application, it fails looking for the included message headers. I'm new to ROS and relatively new to QT so it's probably something obvious in my CMakeLists.txt.

This is my CMakeLists.txt

cmake_minimum_required(VERSION 3.1.0)
project(demointerface)

# set(CMAKE_INCLUDE_CURRENT_DIR ON)
# set(CMAKE_AUTOMOC ON)
# set(CMAKE_AUTOUIC ON)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  message_generation
  std_msgs
  qt_build
)
find_package(yaml-cpp REQUIRED)

# set(Qt5_DIR "/opt/Qt/5.12.0/gcc_64/lib/cmake/Qt5")
# rosbuild_prepare_qt4(QtCore QtGui)

##############################################################################
## Build
##############################################################################
include_directories( ${catkin_INCLUDE_DIRS} )

add_message_files( 
  FILES 
  heartbeatData.msg 
  testCfgData.msg 
  targetCmd.msg
)

generate_messages( DEPENDENCIES std_msgs)

catkin_package(CATKIN_DEPENDS message_runtime)

##############################################################################
# Qt Environment
##############################################################################


find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
message("QT Version: ${Qt5_VERSION}")

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/demointerface/*.hpp)


qt5_add_resources(QT_RESOURCES_CPP ${QT_RESOURCES})
qt5_wrap_ui(QT_FORMS_HPP ${QT_FORMS})
qt5_wrap_cpp(QT_MOC_HPP ${QT_MOC})

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

##############################################################################
# Binaries
##############################################################################
add_executable(demointerface ${QT_SOURCES} ${QT_MOC_HPP} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} )
add_dependencies(demointerface demointerface_generate_messages_cpp)
target_link_libraries(demointerface 
  Qt5::Core
  Qt5::Widgets
  Qt5::Gui
  ${YAML_CPP_LIBRARIES}
  ${catkin_LIBRARIES})
install(TARGETS demointerface RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

ROS Packages: qt_build 2.1.0 roscpp 1.12.14 std_msgs 0.5.11

Platform Information: Ubuntu Xenial 4.15.0-43-generic gcc 5.4.0 Qt 5.5.1 ROS Kinetic

Thanks for the help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-02-04 19:59:33 -0500

robustify gravatar image

All the Qt5 setup looks fine. I think your problem is the add_dependencies line, since it doesn't seem to be properly directing CMake to build your messages before trying to build your node. I use gencpp instead of generate_messages_cpp when I do things like this, and it seems to work fine. Therefore, I would try this add_dependencies command instead:

add_dependencies(demointerface demointerface_gencpp)

On a side note, you can also use the ${PROJECT_NAME} macro to insert the name of the ROS package. This way, it's typo-proof, and will adapt if you ever change the name of the package for some reason. Using this, the above could be written as:

add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_gencpp)

edit flag offensive delete link more

Comments

This didn't end up working for me, I decided to start from the basic catkin_create_qt_pkg and see if I could slowly change it from QT4 to QT5. For whatever reason it works fine. I think something in the ui and corresponding cpp with namespaces are wrong. I'll dig into it and comment back later

goparakeets21 gravatar image goparakeets21  ( 2019-02-05 23:51:42 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-02-03 17:31:06 -0500

Seen: 571 times

Last updated: Feb 04 '19