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

Extending a QT aplication with ROS

asked 2017-05-29 03:36:56 -0500

apalomer gravatar image

updated 2017-05-29 04:04:19 -0500

Hi!

I have a QT application for a project. Now, this has to be integrated with ROS. My idea was to create a derived class of my QT widget and connect the signal from my widget to a function that will publish the ROS message that I want. Is this the right way to do it? Is there any place I can find an example of such thing?

In my QT widget I have the following:

class CameraDisplay : public QMainWindow
{
    Q_OBJECT

public:
    explicit CameraDisplay(QWidget *parent = 0){};
    ...// Other functions and methods
signals:
    void newImage(cv::Mat image);
}

Then, I do not know if I have to derive it as

class ROSCameraDisplay: public CameraDisplay{
    Q_OBJECT
public:

    ROSCameraDisplay():{
        connect(CameraDisplay,SIGNAL(newImage(cv::Mat)),this,SLOT(publish(cv::Mat)));
    }

    ....//Other functions

private slots:
    void publish(cv::Mat img);

or as

class ROSCameraDisplay: public CameraDisplay{
    Q_OBJECT
public:

    ROSCameraDisplay(QWidget* parent): QMainWindow(parent){
        connect(CameraDisplay,SIGNAL(newImage(cv::Mat)),this,SLOT(publish(cv::Mat)));
    }

    ....//Other functions

private slots:
    void publish(cv::Mat img);

In the first case, I get that the vtable for ROSCameraDisplay is undefined. In the second one, I get that QMainWindow is not a direct base of ROSCamDisplay.

I have read about the vtable problem and I know that I get this error because there is some virtual function not instantiated. Does anybody know if there is a way to actually know for which function does it happens? As you can see in the CameraDisplay class, I have no virtual methods and I can instantiate the CameraDisplay class and use the QT interface in another program that only runs this GUI interface.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-05-29 23:17:11 -0500

130s gravatar image

GUI framework in ROS called rqt provides an easy interface to connect your Qt application to ROS network. [This tutorial] is supposed to provide the exact info you need but it's work-in-progress. Hope this link (also referenced from the same tutorial) and also [rqt C++ plugin tutorial] help you.

edit flag offensive delete link more
0

answered 2017-06-07 02:40:40 -0500

apalomer gravatar image

updated 2017-06-07 02:45:52 -0500

Thank you @130s for your answer. I see that all this information is essentially thought to build a plugin for rqt. In my case, it is not what I want. I already have a graphical interface I just want to extend it with ROS. Here is an example similar to what I want to do. This consist of two main windows, one with a place to write text and a button to send it and the second one is used to display the text. By inheriting each one of the main windows, I add the ROS functionalities. The window to send text adds a publisher to publish the text and the window to display it is a bit more complex because I need to create a new thread where the ros::spin() will happen as well as the callback of the messages, the object that will be moved to the new thread will emit a signal for each new message with the message so I can connect this signal to the slot of the display window to set the text. Everything looks like it is working, and I get the published messages from one node in the other. However, the display GUI freezes meaning that I did something wrong in the threading and the QT main thread is blocked somewhere. My questions are:

  1. Does somebody have a hint on why is my QT main thread blocked?
  2. If I want to use rqt how this should be done? All the examples are thought to build a new Widget from scratch, should I just do the same as here but also inheriting from my QMainWindow? I think that can be done if my QT class was a Widget not a MainWindow (which I need for menus), am I right?
edit flag offensive delete link more

Comments

Hi! Did you ever get anywhere with this? I think I'm seeing the same thing, in particular the qt main thread being blocked

joeramsay gravatar image joeramsay  ( 2018-11-18 14:38:38 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-05-29 03:36:56 -0500

Seen: 664 times

Last updated: Jun 07 '17