I'm trying to create a Qt GUI application in ROS Melodic and getting cmake errors.

asked 2021-02-23 14:53:40 -0500

alexspi13 gravatar image

updated 2021-02-23 15:05:46 -0500

Hello guys, I really need your help to finish my Master Thesis. I'm trying to follow this tutorial -> https://www.cnblogs.com/casperwin/p/6... But I'm getting this error:

 CMake Error at qtros/CMakeLists.txt:37 (QT4_ADD_RESOURCES):
  Unknown CMake command "QT4_ADD_RESOURCES".

I have Qt 5 in my computer but in CMakeLists the command : catkin_create_qt_pkg is for QT 4. I can share the CMakeLists if anyone can tell me, what are the necessary changes that I can do, to implement the GUI.

##############################################################################
# CMake
##############################################################################

cmake_minimum_required(VERSION 2.8.0)
project(qtros)

##############################################################################
# Catkin
##############################################################################

# qt_build provides the qt cmake glue, roscpp the comms for a default talker
find_package(catkin REQUIRED COMPONENTS qt_build roscpp)
include_directories(${catkin_INCLUDE_DIRS})
FIND_PACKAGE(Qt4)W
# Use this to define what the package will export (e.g. libs, headers).
# Since the default here is to produce only a binary, we don't worry about
# exporting anything. 
catkin_package()

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

# this comes from qt_build's qt-ros.cmake which is automatically 
# included via the dependency call in package.xml
rosbuild_prepare_qt4(QtCore QtGui) # Add the appropriate components to the component list here

##############################################################################
# Sections
##############################################################################

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.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/qtros/*.hpp)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

##############################################################################
# Sources
##############################################################################

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

##############################################################################
# Binaries
##############################################################################

add_executable(qtros ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(qtros ${QT_LIBRARIES} ${catkin_LIBRARIES})
install(TARGETS qtros RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
edit retag flag offensive close merge delete

Comments

I solve my problem. I post my github repo in case of someone else has the same problem. https://github.com/alexspirou/ROS_Ack...

alexspi13 gravatar image alexspi13  ( 2021-03-12 12:52:53 -0500 )edit