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

How to turn existing Qt widgets into rqt plugin?

asked 2016-12-05 07:58:26 -0500

Azhar gravatar image

updated 2016-12-05 07:59:34 -0500

i have been trying to read all the forums and tutorials , but i dont know where to start. Please guide this noob.

so there are two parts to my question.

i want to make a custom rqt plugin using Qt 5.7. I have already created the user interface in Qt 5.7. so how can i integrate it into ROS(so that it appears as one of the rqt plugins)

a) i have went through the tutorial of how to create a cpp rqt plugin . I dont know what to do after i create all the files(Cmakelist.txt, package.xml, plugin.xml, my_plugin.cpp, my_plugin.h). What to do after that? how can i ensure i can see the rqt plugin in the rqt plugin list. Am i missing anything?

b) this user interface is actually for a moving vehicle(teleoperation). How to use callback/Signal and Slot function to ensure i can communicate(send commands ) via the user interface?

#in Qt, when i click New project -> Import project,i cant see Import ROS project. i tried to run Qt thru terminal but to no avail.

Anyone who could at least guide about how to do would be very beneficial to me. Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2016-12-05 08:17:08 -0500

AndyZe gravatar image

updated 2016-12-06 10:20:40 -0500

I've just done this- it's confusing, right? Especially when the documentation is so spread out. Here are some hints (I'm assuming you're using C++):

A. Start by cloning the example package here. Make sure it compiles and shows up as a plugin.

B. Add your Qt files into that example package. You're going to compile the Widget as a library and link against it. I put the Qt headers into "include/rqt_gauges" and the cpp and ui files into "src/rqt_gauges."

C. In CMakeLists, add the Widget library (for me, it was called "qcgaugewidget":

## The library that defines the Qt stuff

add_library(qcgaugewidget SHARED src/rqt_gauges/qcgaugewidget.cpp)

## Specify libraries to link a library or executable target against

target_link_libraries(qcgaugewidget
  ${catkin_LIBRARIES}
  ${qt_LIBRARIES}
)

D. Now add a library for the plugin. It links against your widget library:

## Declare a cpp library

add_library(${PROJECT_NAME}
    ${rqt_gauges_SRCS}
    ${rqt_gauges_MOCS}
    ${rqt_gauges_UIS_H}
    )

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}
  qcgaugewidget
  ${catkin_LIBRARIES}
  ${qt_LIBRARIES}
)

E. You'll probably run into lots of issues with CMakeLists. It's finnicky. I would just depend on the rqt_gauges example as much as possible.

F. Sorry, I didn't use signals and slots. I hacked it with a pointer instead. Somebody else will have to help you there.

G. You don't need to use QtCreator as your editor. You can use any text editor (even gedit) and compile with catkin_make, like usual for ROS.

edit flag offensive delete link more

Comments

Thank you so much! i am currently stuck in Step A. I can build the it using Qt creator. However, when i run it( Green play icon), a window which says custom executable pops out.I am not sure which is my executable file for this project. Once i figured it, i would continue with the rest of the steps

Azhar gravatar image Azhar  ( 2016-12-06 22:59:28 -0500 )edit
1

Why don't you try building it outside of QtCreator? Assuming you cloned it to ~/Desktop/catkin_ws/src, do this:

cd ~/Desktop/catkin_ws
catkin_make
source ~/Desktop/catkin_ws/devel/setup.bash
rqt --force-discover

Then you should see the plugin.

AndyZe gravatar image AndyZe  ( 2016-12-07 09:59:55 -0500 )edit

Thanks so much for the guidance! This is what i have come up so far.

https://github.com/azhar92/GUI-for-AV.git

However, i am stuck with another error. Would really appreciate if you could help.

Azhar gravatar image Azhar  ( 2016-12-13 04:44:31 -0500 )edit

[ 16%] Building CXX object test1/CMakeFiles/mainwindow.dir/src/rqt_test1/mainwindow.cpp.o

/home/azhar/catkin_ws/src/test1/src/rqt_test1/mainwindow.cpp:2:24: fatal error: mainwindow.h: No such file or directory

#include "mainwindow.h" ^ compilation terminated.

Azhar gravatar image Azhar  ( 2016-12-13 04:46:50 -0500 )edit

compilation terminated. make[2]: * [test1/CMakeFiles/mainwindow.dir/src/rqt_test1/mainwindow.cpp.o] Error 1 make[1]: [test1/CMakeFiles/mainwindow.dir/all] Error 2 make: ** [all] Error 2 Invoking "make -j8 -l8" failed

Azhar gravatar image Azhar  ( 2016-12-13 04:47:34 -0500 )edit
1

That's an easy one. Change it to #include "rqt_test1/mainwindow.h"

AndyZe gravatar image AndyZe  ( 2016-12-13 07:38:39 -0500 )edit

Yeap thanks! That works!

Azhar gravatar image Azhar  ( 2016-12-14 02:18:20 -0500 )edit

Failed to load nodelet [rqt_test1::MyPlugin_1] of type [rqt_test1::MyPlugin]: MultiLibraryClassLoader: Could not create object of class type rqt_test1::MyPlugin as no factory exists for it. Make sure that the library exists and was explicitly loaded through MultiLibraryClassLoader::loadLibrary()

Azhar gravatar image Azhar  ( 2016-12-14 02:19:02 -0500 )edit

RosPluginlibPluginProvider::load_explicit_type(rqt_test1::MyPlugin) failed creating instance PluginManager._load_plugin() could not load plugin "rqt_test1::MyPlugin": RosPluginlibPluginProvider.load() could not load plugin "rqt_test1::MyPlugin

Azhar gravatar image Azhar  ( 2016-12-14 02:19:43 -0500 )edit

^New error which i think something to do with the the plugin.xml or CMakelists and adding target_link_libraries.

Would be great if you could help me out!

Azhar gravatar image Azhar  ( 2016-12-14 02:21:58 -0500 )edit

Hi! I've been following your guidance above. Thank you so much for a lot of help. However, I'm stuck. At this point I get an error similar as above regarding the .h file; catkin_ws/src/rqt_mypkg_test/include/rqt_cpp_test/ui_mainwindow.h:13:29: fatal error: QtWidgets/QAction: No such file or directo

fonstein gravatar image fonstein  ( 2017-01-05 04:30:35 -0500 )edit

The only thing is that it can find the other .h file that is included in the exact same way and located in the same folder. Any ideas why?

fonstein gravatar image fonstein  ( 2017-01-05 04:31:25 -0500 )edit

Also, the example you included in A; I can get the python plugin to work, but not the one for C++. The plugin shows, but it won't show

fonstein gravatar image fonstein  ( 2017-01-05 04:32:25 -0500 )edit

Can you post a link to your repo?

AndyZe gravatar image AndyZe  ( 2017-01-05 09:47:45 -0500 )edit

Sorry for the late reply. Here is my repo: https://github.com/fonstein/rqt_test

fonstein gravatar image fonstein  ( 2017-01-09 04:51:57 -0500 )edit

I fixed the last error, but have a new one: catkin_ws/src/rqt_mypkg_test/include/rqt_cpp_test/my_plugin.h:25:7: error: ‘MyPluginWidget’ in namespace ‘Ui’ does not name a type

fonstein gravatar image fonstein  ( 2017-01-09 07:42:38 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2016-12-05 07:58:26 -0500

Seen: 1,950 times

Last updated: Dec 06 '16