Subscriber from a class compile problems
I am having issues with using a subscriber callback in QT. I have adapted the example as follows:
bool QNode::init() {
ros::init(init_argc,init_argv,"qtest");
if ( ! ros::master::check() ) {
return false;
}
ros::start(); // explicitly needed since our nodehandle is going out of scope.
ros::NodeHandle n;
// Add your ros communications here.
//chatter_publisher = n.advertise<std_msgs::String>("chatter", 1000);
goalReciever = n.subscribe("goalString", 100, &QNode::callback);
start();
return true;
}
inline pcl::PointXY stringToPoint(std::string sPoint)
{
//incoming point will be in the format: "(x, y, theta)"
QString qSPoint = sPoint.c_str();
QString x = qSPoint.section(',', 0, 0);
x.remove(0, 1);
QString y = qSPoint.section(',', 1, 1);
y.remove(0, 1);
QString t = qSPoint.section(',', 2, 2);
t.remove(0, 1); t.remove(t.size() - 1, 1);
pcl::PointXY toReturn;
toReturn.x = x.toDouble();
toReturn.y = y.toDouble();
return toReturn;
}//converts a string to a PCL point.
void QNode::callback(std_msgs::String msg)
{
goal = stringToPoint(msg.data);
}
namespace qtest {
/*****************************************************************************
** Class
*****************************************************************************/
class QNode : public QThread {
Q_OBJECT
public:
QNode(int argc, char** argv );
virtual ~QNode();
bool init();
bool init(const std::string &master_url, const std::string &host_url);
void run();
/*********************
** Logging
**********************/
enum LogLevel {
Debug,
Info,
Warn,
Error,
Fatal
};
QStringListModel* loggingModel() { return &logging_model; }
void log( const LogLevel &level, const std::string &msg);
signals:
void loggingUpdated();
void rosShutdown();
private:
int init_argc;
void callback(std_msgs::String);
char** init_argv;
pcl::PointXY goal;
ros::Publisher chatter_publisher;
ros::Subscriber goalReciever;
QStringListModel logging_model;
};
} // namespace qtest
Of course there are more methods, but I have omitted them from the above. It refuses to compile with errors showing up in the subscriber line. The qt compiler says that the way I set it up doesn't fit the template. How do I fix this?
Thanks,
-Hunter A.