How would you implement a ROS subscriber in an existing QT Creator GUI project?

Viewed 327

I installed the ROS plugin for QT on ubuntu, but if I create a subscriber node in the project it gives me an error on #include "ros / ros.h" From what I understand I need to create a workspace with catkin, but how do I merge the project I already have with the workspace?

1 Answers

If you already have a catkin workspace you simple need to create a new package and build the project there; you can see a tutorial on that here. To put it briefly, you can create a package inside ~/<your_workspace>/src that depends on roscpp this command catkin_create_pkg your_new_package std_msgs roscpp. You should then put your .cpp files in the <your_new_package>/src directory and .hpp files in the <your_new_package>/include directory. All you need to do after that is actually make it build via catkin and cmake. Since ros packages build with cmake this is done by editing the CMakeLists.txt file inside each package. You can find more info on that here. Essentially you want to make sure your source files are captured and build. It could look something like this

cmake_minimum_required(VERSION 2.8.3)
project(your_new_node_name)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs genmsg)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(your_qt_executable src/your_source_file.cpp)
target_link_libraries(your_qt_executable ${catkin_LIBRARIES})
#uncomment this if other deps are needed
#add_dependencies(your_qt_executable some_other_dependency) 
Related