Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link Qt 5.9 in ROS?

The following CMakeList produces errors which have been listed below:

cmake_minimum_required(VERSION 2.8.12)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

project(draw_on_images)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

find_package(OpenCV 2.4.8 REQUIRED)
find_package(Qt5 COMPONENTS Core Qml Quick REQUIRED)


qt5_add_resources(RESOURCES qml.qrc)

catkin_package(
  CATKIN_DEPENDS roscpp rospy std_msgs
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_executable(${PROJECT_NAME} ${RESOURCES} src/main.cpp src/draw_on_qimage.cpp src/provide_qpixmap_to_qml.cpp )

qt5_use_modules(${PROJECT_NAME} Core Qml Quick)

target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Qml Qt5::Quick ${OpenCV_LIBS})

The way I run it:

catkin_make -DCMAKE_PREFIX_PATH="/opt/Qt5.9.1/5.9.1/gcc_64/lib/" -DWITH_QT:BOOL=ON

Yes I have sourced it.

Errors:

Base path: /home/.../ros_workspace_test
Source space: /home/.../ros_workspace_test/src
Build space: /home/.../ros_workspace_test/build
Devel space: /home/.../ros_workspace_test/devel
Install space: /home/.../ros_workspace_test/install
####
#### Running command: "cmake /home/.../ros_workspace_test/src -DCMAKE_PREFIX_PATH=/opt/Qt5.9.1/5.9.1/gcc_64/lib/ -DWITH_QT:BOOL=ON -DCATKIN_DEVEL_PREFIX=/home/.../ros_workspace_test/devel -DCMAKE_INSTALL_PREFIX=/home/.../ros_workspace_test/install -G Unix Makefiles" in "/home/.../ros_workspace_test/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/.../ros_workspace_test/devel
-- Using CMAKE_PREFIX_PATH: /opt/Qt5.9.1/5.9.1/gcc_64/lib/
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/.../ros_workspace_test/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.19
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - draw_on_images
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'draw_on_images'
-- ==> add_subdirectory(draw_on_images)
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    WITH_QT


-- Build files have been written to: /home/.../ros_workspace_test/build
####
#### Running command: "make -j4 -l4" in "/home/.../ros_workspace_test/build"
####
[ 14%] Automoc for target draw_on_images
[ 14%] Built target draw_on_images_automoc
Linking CXX executable /home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `int qmlRegisterType<Draw_on_qimage>(char const*, int, int, char const*)':
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x38): undefined reference to `Draw_on_qimage::staticMetaObject'
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x1b6): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Draw_on_qimage::~Draw_on_qimage()':
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x13): undefined reference to `vtable for Draw_on_qimage'
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x25): undefined reference to `vtable for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QMetaTypeIdQObject<Draw_on_qimage*, true>::qt_metatype_id()':
main.cpp:(.text._ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv[_ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv]+0x2c): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QtPrivate::MetaObjectForType<Draw_on_qimage*, true>::value()':
main.cpp:(.text._ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv[_ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv]+0x7): undefined reference to `Draw_on_qimage::staticMetaObject'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `Draw_on_qimage::metaObject() const'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x18): undefined reference to `Draw_on_qimage::qt_metacast(char const*)'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x20): undefined reference to `Draw_on_qimage::qt_metacall(QMetaObject::Call, int, void**)'
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `typeinfo for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Provide_QPixmap_to_QML::~Provide_QPixmap_to_QML()':
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x13): undefined reference to `vtable for Provide_QPixmap_to_QML'
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x25): undefined reference to `vtable for Provide_QPixmap_to_QML'
CMakeFiles/draw_on_images.dir/src/draw_on_qimage.cpp.o: In function `Draw_on_qimage::Draw_on_qimage(QQuickPaintedItem*)':
draw_on_qimage.cpp:(.text+0x4b): undefined reference to `vtable for Draw_on_qimage'
draw_on_qimage.cpp:(.text+0x5d): undefined reference to `vtable for Draw_on_qimage'
CMakeFiles/draw_on_images.dir/src/provide_qpixmap_to_qml.cpp.o: In function `Provide_QPixmap_to_QML::Provide_QPixmap_to_QML()':
provide_qpixmap_to_qml.cpp:(.text+0x52): undefined reference to `vtable for Provide_QPixmap_to_QML'
provide_qpixmap_to_qml.cpp:(.text+0x64): undefined reference to `vtable for Provide_QPixmap_to_QML'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images] Error 1
make[1]: *** [draw_on_images/CMakeFiles/draw_on_images.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

How to link Qt 5.9 in ROS?

I am using Ubuntu 14.

like image 595
Aquarius_Girl Avatar asked Dec 09 '17 08:12

Aquarius_Girl


People also ask

Why use qtcreator and not Ros?

#### Why use Qtcreatorand not ROS Qt (rqt) rqt is great for ‘quick and dirty’ UI where-by you can fix together different plugins (or make your own plugin) in a dockable window. However, if you want to make highly customized UI with your own graphics asset, animation, and granular control, creating a Qt application is a better option.

How do Ros and Qt communicate with each other?

Qt communication framework Similar to ROS’s communication framework, different Qt objects can communicate to each other through trigger events. However, instead of using Publisher/Subscriber system like in ROS, Qt uses signal/slot system.

What is rqt_joint_trajectory?

rqt_joint_trajectory... qt_gui provides the infrastructure for an integrated graphical user interface based on Qt. It is extensible with Python- and C++-based plugins (implemented in separate packages) which can contribute arbitrary widgets. It requires either PyQt or PySide bindings.

Should I use static or dynamic linking in Qt?

In some cases, using static linking may be preferable; it avoids the dependencies to external libraries, produces single, self-contained application binaries making deployment easier, and may lead to smaller binary size as unused code can be stripped away. Internally, Qt uses dynamic linking with plugins for a lot of its functionality.


1 Answers

Solution was to add the header files to add_executable in CMakelists.txt:

add_executable(${PROJECT_NAME} ${RESOURCES}
                               src/main.cpp 
                               include/draw_on_images/draw_on_qimage.h src/draw_on_qimage.cpp
                               include/draw_on_images/provide_qpixmap_to_qml.h src/provide_qpixmap_to_qml.cpp)
like image 150
Aquarius_Girl Avatar answered Oct 22 '22 09:10

Aquarius_Girl