Ask Your Question

Subscriber from a class compile problems

asked 2012-04-06 13:32:06 -0500

allenh1 gravatar image

updated 2014-01-28 17:11:54 -0500

ngrennan gravatar image

I am having issues with using a subscriber callback in QT. I have adapted the example as follows:

bool QNode::init() {
    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);
    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(;

namespace qtest {

** Class

class QNode : public QThread {
    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 {

    QStringListModel* loggingModel() { return &logging_model; }
    void log( const LogLevel &level, const std::string &msg);

    void loggingUpdated();
    void rosShutdown();

    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?


-Hunter A.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-04-06 14:40:10 -0500

Eric Perko gravatar image

You need to pass a pointer to your class object. For example, something like

  goalReciever = n.subscribe("goalString", 100, &QNode::callback, this);

See the roscpp docs for details on valid callback signatures.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-04-06 13:32:06 -0500

Seen: 757 times

Last updated: Apr 06 '12