Boost logo

Boost Users :

Subject: [Boost-users] [function / bind] How to register callbacks using boost::function/bind?
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2013-02-04 03:39:57


Hi all,

I am trying to use a callback mechanism for logging in my app. I thus have
a class with :

class coordinates_converter

{

public:

    coordinates_converter(int id);

    ~coordinates_converter();

    void register_error_callback (const
boost::function<void(std::string message)> &callback ) {
_error_callback = callback; }

private:

    boost::function<void(std::string message)> _error_callback;

}

Now, if I want to register a log error callback in another object instance,
how should I do this? Cannot find the right syntax ...

void another_class::do()

{

    acute_coordinates_converter* converter = new coordinates_converter(2154);

    converter->register_error_callback(
boost::bind(&another_class::log_error, converter, _1) );

}

where log_error is a Qt SIGNAL:

signals:

    void log_error(const std::string& error);

Hope you could help.

Rehads,

Olivier



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net