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

Revision history [back]

click to hide/show revision 1
initial version

dornhege,thanks very much!! Your reply lets me know about how to incorporate ROS and Qt, and the errors on my first post disappear, but it exists special errors:

              error: expected ‘:’ before ‘slots’;;
              error: ‘slots’ does not name a type
              error: ‘signals’ does not name a type

However, in the definition of this class, I do have declare the " Q_OBJECT " And the head file is: #include <qlabel> #include <qstring>

                  #ifndef HELLOWIDGET_H_
                  #define HELLOWIDGET_H_

                  class HelloWidget : public QLabel {
                              Q_OBJECT
                    public:
                          HelloWidget(QWidget * parent = 0);
                          ~HelloWidget();

                    public slots:
                              void showNewLetter();

                    protected:
                          QString _msg;
                          unsigned short _pos;
                    signals:
                              woid showNewLetter1(); //just for test
                    };
                   #endif /* HELLOWIDGET_H_ */

According to the answer, my new CMakeList.txt is:

              cmake_minimum_required(VERSION 2.4.6)
              include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

               rosbuild_init()

              find_package(Qt4 REQUIRED)
              # enable/disable some Qt features
               set( QT_USE_QTGUI TRUE )
               set( QT_USE_QTOPENGL TRUE )
               set( QT_USE_QTXML TRUE )
               include(${QT_USE_FILE})

               ADD_DEFINITIONS(-DQT_NO_KEYWORDS)

               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(qt_srcs
                         HelloWidget.cpp
                         MainWindow.cpp
                    )
               set(qt_hdrs
                         HelloWidget.h
                          MainWindow.h
                    )
               qt4_automoc(${qt_srcs})
               QT4_WRAP_CPP(qt_moc_srcs ${qt_hdrs})

               QT4_WRAP_UI(uis_h HelloWidget.ui)

                # include this for ui_h
                include_directories(${CMAKE_CURRENT_BINARY_DIR})

                #uncomment if you have defined messages
                 rosbuild_genmsg()

               rosbuild_add_executable(turtle_teleop_joy teleop_turtle_joy.cpp
                          ${uis_h} ${qt_srcs} ${qt_moc_srcs})

               target_link_libraries(turtle_teleop_joy ${QT_LIBRARIES})

Why I has this strange errors on my compiler, is because I lack of some Qt features, but I do not find any other features on web, or anywhere setting on my CMakeList.txt or the configuration of my Qt creator? Can anyone give me a hint? Thanks all the same!

dornhege,thanks very much!! Your reply lets me know about how to incorporate ROS and Qt, and the errors on my first post disappear, but it exists special errors:

              error: expected ‘:’ before ‘slots’;;
              error: ‘slots’ does not name a type
              error: ‘signals’ does not name a type

However, in the definition of this class, I do have declare the " Q_OBJECT " And the head file is: #include <qlabel> #include <qstring>is:

                  #include <QLabel>
                  #include <QString>
                  #ifndef HELLOWIDGET_H_
                  #define HELLOWIDGET_H_

                  class HelloWidget : public QLabel {
                              Q_OBJECT
                    public:
                          HelloWidget(QWidget * parent = 0);
                          ~HelloWidget();

                    public slots:
                              void showNewLetter();

                    protected:
                          QString _msg;
                          unsigned short _pos;
                    signals:
                              woid showNewLetter1(); //just for test
                    };
                   #endif /* HELLOWIDGET_H_ */

According to the answer, my new CMakeList.txt is:

              cmake_minimum_required(VERSION 2.4.6)
              include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

               rosbuild_init()

              find_package(Qt4 REQUIRED)
              # enable/disable some Qt features
               set( QT_USE_QTGUI TRUE )
               set( QT_USE_QTOPENGL TRUE )
               set( QT_USE_QTXML TRUE )
               include(${QT_USE_FILE})

               ADD_DEFINITIONS(-DQT_NO_KEYWORDS)

               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(qt_srcs
                         HelloWidget.cpp
                         MainWindow.cpp
                    )
               set(qt_hdrs
                         HelloWidget.h
                          MainWindow.h
                    )
               qt4_automoc(${qt_srcs})
               QT4_WRAP_CPP(qt_moc_srcs ${qt_hdrs})

               QT4_WRAP_UI(uis_h HelloWidget.ui)

                # include this for ui_h
                include_directories(${CMAKE_CURRENT_BINARY_DIR})

                #uncomment if you have defined messages
                 rosbuild_genmsg()

               rosbuild_add_executable(turtle_teleop_joy teleop_turtle_joy.cpp
                          ${uis_h} ${qt_srcs} ${qt_moc_srcs})

               target_link_libraries(turtle_teleop_joy ${QT_LIBRARIES})

Why I has this strange errors on my compiler, is because I lack of some Qt features, but I do not find any other features on web, or anywhere setting on my CMakeList.txt or the configuration of my Qt creator? Can anyone give me a hint? Thanks all the same!

dornhege,thanks very much!! Your reply lets me know about how to incorporate ROS and Qt, and the errors on my first post disappear, but it exists special errors:

              error: expected ‘:’ before ‘slots’;;
              error: ‘slots’ does not name a type
              error: ‘signals’ does not name a type

However, in the definition of this class, I do have declare the " Q_OBJECT " And the head file is:

                  #include <QLabel>
                  #include <QString>
                  #ifndef HELLOWIDGET_H_
                  #define HELLOWIDGET_H_

                  class HelloWidget : public QLabel {
                              Q_OBJECT
                    public:
                          HelloWidget(QWidget * parent = 0);
                          ~HelloWidget();

                    public slots:
                              void showNewLetter();

                    protected:
                          QString _msg;
                          unsigned short _pos;
                    signals:
                              woid void showNewLetter1(); //just for test
                    };
                   #endif /* HELLOWIDGET_H_ */

According to the answer, my new CMakeList.txt is:

              cmake_minimum_required(VERSION 2.4.6)
              include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

               rosbuild_init()

              find_package(Qt4 REQUIRED)
              # enable/disable some Qt features
               set( QT_USE_QTGUI TRUE )
               set( QT_USE_QTOPENGL TRUE )
               set( QT_USE_QTXML TRUE )
               include(${QT_USE_FILE})

               ADD_DEFINITIONS(-DQT_NO_KEYWORDS)

               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(qt_srcs
                         HelloWidget.cpp
                         MainWindow.cpp
                    )
               set(qt_hdrs
                         HelloWidget.h
                          MainWindow.h
                    )
               qt4_automoc(${qt_srcs})
               QT4_WRAP_CPP(qt_moc_srcs ${qt_hdrs})

               QT4_WRAP_UI(uis_h HelloWidget.ui)

                # include this for ui_h
                include_directories(${CMAKE_CURRENT_BINARY_DIR})

                #uncomment if you have defined messages
                 rosbuild_genmsg()

               rosbuild_add_executable(turtle_teleop_joy teleop_turtle_joy.cpp
                          ${uis_h} ${qt_srcs} ${qt_moc_srcs})

               target_link_libraries(turtle_teleop_joy ${QT_LIBRARIES})

Why I has this strange errors on my compiler, is because I lack of some Qt features, but I do not find any other features on web, or anywhere setting on my CMakeList.txt or the configuration of my Qt creator? Can anyone give me a hint? Thanks all the same!