ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Extending a QT aplication with ROS

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:
...// 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:

}

....//Other functions

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


or as

class ROSCameraDisplay: public CameraDisplay{
Q_OBJECT
public:

}

....//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 close merge delete

Sort by » oldest newest most voted

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?
more

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

( 2018-11-18 14:38:38 -0600 )edit

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.

more