ROS Qt creator GUI
Hi, everyone, I am a freshman on ROS and Qt. Sorry to post long question in next, I am overwhelming by incorporate Qt GUI in ROS for almost 4 days, I follow the former posts, post1, and post2 and their related links, and thanks for their answers, I could use Qt creator to compile the ROS packages. However, when I try to bind the Qt program to ROS program, I do not find way to do, (mainly on the CMakeList.txt ). So next is my question: I want to build a simple interface to play with the turtle in learning_joy package instead of using joystick.
According to the tutorials on joystick, I could control the turtle with my joystick. So I use the CMakeList.txt as the copy to add some Qt creator CMake inside. The original learing_joy CMakeList.txt is
cmake_minimum_required(VERSION 2.4.6) include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
#set(ROS_BUILD_TYPE RelWithDebInfo) rosbuild_init() #set the default path for built executables to the "bin" directory set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) #set the default path for built libraries to the "lib" directory set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) # Set the example from the Qt #uncomment if you have defined messages rosbuild_genmsg() #uncomment if you have defined services #rosbuild_gensrv() #common commands for building c++ executables and libraries #rosbuild_add_library(${PROJECT_NAME} src/example.cpp) #target_link_libraries(${PROJECT_NAME} another_library) #rosbuild_add_boost_directories() #rosbuild_link_boost(${PROJECT_NAME} thread) #rosbuild_add_executable(example examples/example.cpp) rosbuild_add_executable(turtle_teleop_joy src/teleop_turtle_joy.cpp) #target_link_libraries(example ${PROJECT_NAME})
By searching CMake and Qt example, I find one example "HelloworldQt", which includes 5 files: HelloWidget.cpp, HelloWidget.h, Mainwindow.cpp, MainWindow.h, and main.cpp, I also ran this Qt project on my Qt creator,
it's CMakeList.txt is"
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(HelloWorldQt)
SET( HWQ_LIB ${QT_LIBRARIES} )SET(CMAKE_BUILD_TYPE Release) SET(CMAKE_CXX_FLAGS "-Wall") # QT4 Handling FIND_PACKAGE(Qt4 REQUIRED) INCLUDE(${QT_USE_FILE}) SET( HWQ_Qt4_SRC src/MainWindow.h src/HelloWidget.h ) SET( HWQ_Qt4_UI ) SET( HWQ_Qt4_RES ) QT4_WRAP_CPP(HWQ_MOC_CPP ${HWQ_Qt4_SRC}) QT4_WRAP_UI(HWQ_UI_CPP ${HWQ_Qt4_UI}) QT4_ADD_RESOURCES(HWQ_RES_H ${HWQ_Qt4_RES}) INCLUDE_DIRECTORIES( . ) # General SET( HWQ_SRC src/main.cpp src/MainWindow.cpp src/HelloWidget.cpp ${HWQ_MOC_CPP} ${HWQ_UI_CPP} ${HWQ_RES_H} )
ADD_EXECUTABLE(HelloWorldQt ${HWQ_SRC} ) TARGET_LINK_LIBRARIES(HelloWorldQt ${HWQ_LIB} ) INSTALL_TARGETS( /bin HelloWorldQt)"
- So I want to incorporate these two files as one, and combine the main.cpp and add
#include <qtgui qapplication="">
#include "MainWindow.h"
#include <qlabel>
#include <qstring>
#include <qvboxlayout>
in teleop_turtle_joy.cpp, but I find no matter what sequences I put these CMakeLists files, it can run CMake, but when I build, Qt creator show "
error: undefined reference to
QMainWindow::QMainWindow(QWidget*, QFlags<Qt::WindowType>); error: undefined reference to
vtable for MainWindow" and etc,
- So I want to incorporate these two files as one, and combine the main.cpp and add
#include <qtgui qapplication="">
#include "MainWindow.h"
#include <qlabel>
#include <qstring>
#include <qvboxlayout>
in teleop_turtle_joy.cpp, but I find no matter what sequences I put these CMakeLists files, it can run CMake, but when I build, Qt creator show "
error: undefined reference to
For the second kind of error, it because lacking moc files, so my incorporated cMakeList does not produce moc files, but why? It looks that combined CMakeList.txt really run on the ROS, but it does not produce the same file as when I only run HelloWidget, which produces the moc files for two **.cpp. So can you point one or more direction for me?
the corporated CMakeList.txt "
cmake_minimum_required(VERSION 2.4.6)
PROJECT(learning_joy)
# Set ...