Note that there are some explanatory texts on larger screens.

plurals
  1. POImage not getting displayed/update in QLabel using SIGNAL-SLOT in ROS node
    primarykey
    data
    text
    <p>I am implementing the Qt code in ROS node. I have a header file in which i have defined all the members, Q_SIGNAL and Q_SLOTS. In my .cpp file i want to display an image when i press a button(assignButton). But when i press the button, nothing shows up. </p> <p>To test whether the connect function is working properly or not, i tried to display an image in the imageLabel which is stored in my laptop..and it worked. </p> <p><strong>PROBLEM:-</strong> I am taking the images from simulator in ROS through the <code>void SelectionInterface::imageCallback(const sensor_msgs::ImageConstPtr&amp; msg)</code> and i want to display those images in imageLabel by SIGNAL-SLOT..but its not getting displayed..no error</p> <p>My code is following:-</p> <p><strong>1. Header file-- SelectionInterface.h</strong></p> <pre><code>class SelectionInterface : public QMainWindow { Q_OBJECT public: SelectionInterface(ros::NodeHandle *nh, RosThread *rt, QMainWindow *parent = 0); ~SelectionInterface(); private: RosThread *rosThread; ros::NodeHandle *nodeHandle; // ROS Subscribers image_transport::Subscriber image_sub; void imageCallback(const sensor_msgs::ImageConstPtr&amp; msg); // More Memberfunctions and Variables QWidget *newCentralWidget; QPushButton *quitButton; QPushButton *assignButton; QVBoxLayout *layout; QLabel *imageLabel; QImage image; // ... protected: void closeEvent(QCloseEvent *event); Q_SIGNALS: void windowClosedSignal(); private Q_SLOTS: void quitInterface(); void assignImage();//QImage }; </code></pre> <p><strong>2. .cpp file</strong></p> <pre><code>#include "SelectionInterface.h" #include &lt;iostream&gt; SelectionInterface::SelectionInterface(ros::NodeHandle *nh, RosThread *rt, QMainWindow *parent): QMainWindow (parent) { rosThread = rt; nodeHandle = nh; // Subscribing and Publishing image_transport::ImageTransport it(*nh); // Setup user interface here newCentralWidget = new QWidget; quitButton = new QPushButton("Quit"); assignButton = new QPushButton("Assign Image"); layout = new QVBoxLayout; imageLabel = new QLabel; imageLabel-&gt;setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layout-&gt;addWidget(imageLabel); layout-&gt;addWidget(quitButton); layout-&gt;addWidget(assignButton); newCentralWidget-&gt;setLayout(layout); this-&gt;setCentralWidget(newCentralWidget); // Signal-Slot Connections connect(this, SIGNAL(windowClosedSignal()), this, SLOT(quitInterface())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); connect(assignButton, SIGNAL(clicked()), this, SLOT(assignImage())); // ... } void SelectionInterface::imageCallback(const sensor_msgs::ImageConstPtr&amp; msg) { QImage image(&amp;(msg-&gt;data[0]), msg-&gt;width, msg-&gt;height, QImage::Format_RGB888); } SelectionInterface::~SelectionInterface() { //destructer (leave empty) } void SelectionInterface::closeEvent(QCloseEvent *event) { Q_EMIT windowClosedSignal(); } void SelectionInterface::quitInterface() { rosThread-&gt;stop(); rosThread-&gt;wait(); std::cout &lt;&lt; "Good bye.\n"; } void SelectionInterface::assignImage() { imageLabel-&gt;setPixmap(QPixmap::fromImage(image)); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload