Robotics StackExchange | Archived questions

main_window.hpp:73: error: no matching function for call to 'ros::NodeHandle::subscribe(const char [9], int, <unresolved overloaded function type>)

Respected all,

I am trying to get feedback from the servo motor, for that i have created a publisher in another machine but when i try to write a code for publisher in QT it shows mw following error:

All network stuffs are working fine.

/home/darshan/catkinws/src/abc/include/abc/mainwindow.hpp:73: error: no matching function for call to 'ros::NodeHandle::subscribe(const char [9], int, )'

please consider my main_window.hpp file:

 #ifndef abc_MAIN_WINDOW_H
#define abc_MAIN_WINDOW_H

      /*****************************************************************************
     ** Includes
     *****************************************************************************/

         #include <QtGui/QMainWindow>
         #include "ui_main_window.h"
      #include "qnode.hpp"
    #include <QtSerialPort/QSerialPort>
        #include <ros/ros.h>
      #include "std_msgs/String.h"
      #include "std_msgs/UInt16.h"

     /*****************************************************************************
       ** Namespace
      *****************************************************************************/
     namespace abc {

    class MainWindow : public QMainWindow {
     Q_OBJECT

    public:
MainWindow(int argc, char** argv, QWidget *parent = 0);
~MainWindow();

    public Q_SLOTS:
/******************************************
** Auto-connections (connectSlotsByName())
*******************************************/
void on_pushButton_clicked();
void on_horizontalSlider_valueChanged(int value);
  void chatterCallback();

/******************************************
** Manual connections
*******************************************/
 private:
Ui::MainWindowDesign ui;
ros::NodeHandle n;
std_msgs::UInt16 fb_msg;
    ros::Publisher chatter_pub = n.advertise<std_msgs::UInt16>("chatter", 1000);
    ros::Subscriber sub = n.subscribe("chatter1",1000, chatterCallback);
QSerialPort *arduino;
QNode qnode;
};
}  // namespace abc
#endif // abc_MAIN_WINDOW_H

Now cosider this main_window.cpp file:

   /*****************************************************************************
   ** Includes
    *****************************************************************************/
    #include <ros/ros.h>
    #include <QtGui>
    #include <QMessageBox>
    #include <QtSerialPort/QSerialPort>
    #include <iostream>
    #include <QtSerialPort/QSerialPortInfo>
    #include <QDebug>
    #include <QWidget>
    #include "../include/abc/main_window.hpp"
    #include <std_msgs/UInt16.h>
    #include "std_msgs/String.h"
     #include <sstream>

 /*****************************************************************************
 ** Namespaces
 *****************************************************************************/
 namespace abc {
 using namespace Qt;
 QSerialPort *serial;
 MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
: QMainWindow(parent)
, qnode(argc,argv)
 {
    ui.setupUi(this);
 }
 MainWindow::~MainWindow() {}
 void MainWindow::on_pushButton_clicked()
 {
     ui.label_4->setText("Hello, Please use Slider to control your Servo");
 }
  void MainWindow::on_horizontalSlider_valueChanged(int value)
 {
  ui.label_5->setText(QString("%1").arg(value));
   std_msgs::UInt16 msg;
   msg.data = ui.label_5->text().toUInt();
   ROS_INFO("%d", msg.data);
  chatter_pub.publish(msg);
   ros::spinOnce();
  }

  void MainWindow::chatterCallback(&fb_msg)
 {
  ROS_INFO("I heard: [%d]", &fb_msg);
  }
  }   // namespace abc

and main.cpp file : /***************************************************************************** ** Includes *****************************************************************************/

#include <QtGui>
#include <ros/ros.h>
#include <QApplication>
#include "../include/abc/main_window.hpp"
#include "std_msgs/String.h"
#include <sstream>

  /*****************************************************************************
   ** Main
   *****************************************************************************/

int main(int argc, char **argv) {
ros::init(argc, argv, "talker");


/*********************
** Qt
**********************/
QApplication app(argc, argv);


abc::MainWindow w(argc,argv);
w.show();
w.setWindowTitle("GUI for Controlling Servo Motor");
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
int result = app.exec();
return result;
}

I request you all to help me to find out the solution of this error.

Asked by darshandoria on 2015-10-05 03:31:17 UTC

Comments

you just need to link Qserialport library inside your cmakelist.txt Same as the following link -- http://stackoverflow.com/questions/34128686/how-do-i-add-qserialport-module-into-cmake
But there is something to resolve (i dont know how yet ) because we are using in a different QThread.

Asked by Alymna on 2016-08-18 11:14:57 UTC

Answers