
I am building a widget set using the signals and slots library. I have
the need to be able create a functor (FA) that receives another (FB) as
an argument to its constructor. I will connect FA to the signal of a
widget, when FA is run it will perform a test and execute FB if
appropriate. I want to be able to use the signal member of another
widget as FB, so I am trying to use bind to get that function object for
the signal. I am experiencing two problems:
1) When the member functor (FB) is bound to the signal of another
widget, the slots don't get called. (No error results, but the connected
slot doesn't print anything so I am assuming it isn't being executed).
2) I can't get it to compile when the signal has a

Darren Vincent Hart wrote: [...]
struct widget { boost::signal
sig; boost::signal keypress; bool test() { cout << "widget::test() - sig empty: " << (sig.empty() ? "true" : "false") << endl; sig(); return true; } }; [...] // bind to a widget signal handler, BROKEN //handler<bool> handler_b( boost::bind<bool>(&widget::sig, &widget_a) ); // <-- Broken [...] // store the function object returned by binding a widget signal, BROKEN //boost::function fp = boost::bind(&widget::sig, &widget_a); // <-- BROKEN // executre the functor returned by binding a widget signal, BROKEN // (builds, but doesn't really call widget_a.sig()) boost::bind(&widget::sig, &widget_a)(); // <-- Test if binding works at all, it doesn't
bind(&widget::sig, &widget_a)() gets you a reference to widget_a->sig since
&widget::sig is a data member. You still need to call it.
bool call(signal

OK, this group finally let me replay to the list.
I added the header file for apply and changed the line you mentioned
to use apply<bool>(), but now it won't compile, comlaining about
noncopyable objects. Any thoughts?
---snip---
old_test.cpp:87: instantiated from here
/usr/include/boost/noncopyable.hpp:27: error: `
boost::noncopyable::noncopyable(const boost::noncopyable&)' is private
/usr/include/boost/bind.hpp:186: error: within this context
/usr/include/boost/bind.hpp: In member function `R
boost::_bi::list1<A1>::operator()(boost::_bi::type<R>, F, A&) const
[with R
= bool, F = boost::apply<bool>, A = boost::_bi::list0, A1 =
boost::_bi::bind_t
Darren Vincent Hart wrote: [...]
struct widget { boost::signal
sig; boost::signal keypress; bool test() { cout << "widget::test() - sig empty: " << (sig.empty() ? "true" : "false") << endl; sig(); return true; } }; [...] // bind to a widget signal handler, BROKEN //handler<bool> handler_b( boost::bind<bool>(&widget::sig, &widget_a) ); // <-- Broken [...] // store the function object returned by binding a widget signal, BROKEN //boost::function fp = boost::bind(&widget::sig, &widget_a); // <-- BROKEN // executre the functor returned by binding a widget signal, BROKEN // (builds, but doesn't really call widget_a.sig()) boost::bind(&widget::sig, &widget_a)(); // <-- Test if binding works at all, it doesn't
bind(&widget::sig, &widget_a)() gets you a reference to widget_a->sig since &widget::sig is a data member. You still need to call it.
bool call(signal
const & s) { return s(); } bind(call, bind(&widget::sig, &widget_a)) ();
will probably do what you want.
You can use apply<> from
instead of 'call': bind(apply<bool>(), bind(&widget::sig, &widget_a)) (); // should call widget_a->sig
HTH
participants (3)
-
Darren Vincent Hart
-
darrenvhart
-
Peter Dimov