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

QtCreator + ROS error: expected ‘:’ before ‘slots’

asked 2019-07-07 04:28:57 -0600

Amrello gravatar image

updated 2019-10-10 11:12:14 -0600

I am trying to use QtCreator to compile project from tutorial (https://www.bbsmax.com/A/RnJW7r6wJq/) and it compiles well, but get errors when I try to add some elements thought the QtDesigner.

In file included from /home/neboron/robo_ws/build/robo1/include/robo1/moc_main_window.cxx:9:0:
/home/neboron/robo_ws/build/robo1/include/robo1/../../../../src/robo1/include/robo1/main_window.hpp:57:9: error: expected ‘:’ before ‘slots’
 private slots:
         ^~~~~
/home/neboron/robo_ws/build/robo1/include/robo1/../../../../src/robo1/include/robo1/main_window.hpp:57:9: 

error: ‘slots’ does not name a type
    robo1/CMakeFiles/robo1.dir/build.make:178: recipe for target 'robo1/CMakeFiles/robo1.dir/include/robo1/moc_main_window.cxx.o' failed
    make[2]: *** [robo1/CMakeFiles/robo1.dir/include/robo1/moc_main_window.cxx.o] Error 1

make[2]: *** Ожидание завершения заданий…
In file included from /home/neboron/robo_ws/src/robo1/src/main.cpp:14:0:
/home/neboron/robo_ws/src/robo1/src/../include/robo1/main_window.hpp:57:9: error: expected ‘:’ before ‘slots’
 private slots:
         ^~~~~
/home/neboron/robo_ws/src/robo1/src/../include/robo1/main_window.hpp:57:9: error: ‘slots’ does not name 
a type

In file included from /home/neboron/robo_ws/src/robo1/src/main_window.cpp:15:0:
/home/neboron/robo_ws/src/robo1/src/../include/robo1/main_window.hpp:57:9: error: expected ‘:’ before ‘slots’
 private slots:
         ^~~~~
/home/neboron/robo_ws/src/robo1/src/../include/robo1/main_window.hpp:57:9: error: ‘slots’ does not name a type
robo1/CMakeFiles/robo1.dir/build.make:82: recipe for target 'robo1/CMakeFiles/robo1.dir/src/main.cpp.o' failed
make[2]: *** [robo1/CMakeFiles/robo1.dir/src/main.cpp.o] Error 1
robo1/CMakeFiles/robo1.dir/build.make:106: recipe for target 'robo1/CMakeFiles/robo1.dir

/src/main_window.cpp.o' failed
make[2]: *** [robo1/CMakeFiles/robo1.dir/src/main_window.cpp.o] Error 1
CMakeFiles/Makefile2:595: recipe for target 'robo1/CMakeFiles/robo1.dir/all' failed
make[1]: *** [robo1/CMakeFiles/robo1.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

But I havent "add_definitions(-DQT_NO_KEYWORDS)" inclusion in my CMakeLists:

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

cmake_minimum_required(VERSION 2.8.0)
project(robo1)

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

# qt_build provides the qt cmake glue, roscpp the comms for a default talker
find_package(Qt4 REQUIRED)
find_package(catkin REQUIRED COMPONENTS qt_build roscpp)
include_directories(${catkin_INCLUDE_DIRS})


# 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/robo1/*.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(robo1 ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(robo1 ${QT_LIBRARIES} ${catkin_LIBRARIES})
install(TARGETS robo1 RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

I can't figure why ... (more)

edit retag flag offensive close merge delete

Comments

1

You added the ros2tag to this question, yet the tutorial you are following (https://www.bbsmax.com/A/RnJW7r6wJq/) is for ROS1. Are you trying to create a GUI for ROS2?

Tav_PG gravatar image Tav_PG  ( 2019-10-09 19:53:40 -0600 )edit

Sorry, I mistakenly added this tag. I use ROS melodic.

Amrello gravatar image Amrello  ( 2019-10-10 10:19:14 -0600 )edit

Hello, just 2 quick information that will not resolve your problem, but can help :

1) You can use RQT for ROS application : http://wiki.ros.org/rqt , it's more integrated with ROS and up to date (but maybe you don't want to be integrated for some application)

2) The tutorial seem to target ROS Kinetic or older (The post is from 2016-12-21), and you are using melodic (released in may 2018), maybe you should use Kinetic if you can (I don't recommend it on the very long term since Kinetic will be EOL in May 2021, but maybe it's a short term project and switching distro can help)

lmathieu gravatar image lmathieu  ( 2019-10-10 11:39:43 -0600 )edit

I have the same problem with Kinetic

MartensCedric gravatar image MartensCedric  ( 2020-05-28 12:21:04 -0600 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2019-10-16 19:31:15 -0600

jschornak gravatar image

Try using Q_SLOTS instead of slots.

I think the underlying issue is that QtDesigner expects to compile with qmake, while ROS packages compile with CMake. Some of the macros used by Qt C++ applications (like slots) don't behave well under CMake.

edit flag offensive delete link more

Comments

My issue is that this error happens in /opt/ros/kinetic/include/qt_gui_cpp/plugin_bridge.h:63: and I can't easily modify it, especially if I want my code to run on other people's PC. When I add remove_definitions(-DQT_NO_KEYWORDS), the error disappears but then I get a linking error with moc

MartensCedric gravatar image MartensCedric  ( 2020-05-28 12:29:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-07 04:28:57 -0600

Seen: 1,240 times

Last updated: Oct 16 '19