connecting a function to a boost::signal runs, but doesn't call the function
I have a class Yarl
in my code with a member function refresh
that I want to bind to two boost::signal
s. One of these signals is a member of a class EventHandler
defined like this:
class EventHandler {
public:
boost::signal<void()> sigRefresh;
};
The other is a free floating signal in another file declared like this:
namespace utility {
static boost::signal<void()> signal_refresh;
}
in a member function of Yarl
, I connect refresh
to the signals like this:
events::EventHandler eventHandler;
eventHandler.sigRefresh.connect(boost::bind(&Yarl::refresh, this));
utility::signal_refresh.connect(boost::bind(&Yarl::refresh, this));
and later on I call both signals like this:
sigRefresh();
signal_refresh();
This code compiles and runs, and sigRefresh
works exactly as expected. However, nothing happens when I call signal_refresh
. As far as I can tell, refresh
never actually got connected to signal_refresh
. Anyone see what I'm doing wr开发者_开发技巧ong?
I'm taking a guess that you are multiply defining signal_refresh. The static keyword before it's declaration suggests to me the code snippet is in a header file and you had to put the static there to get it to compile without redefined symbol errors. If you have done this then every source file including the header will get a unique copy of signal_refresh and thus the instance you are calling may not be the instance you connected it to.
I may be totally off mark here but it is possible.
精彩评论