sigc++ compatible with wxWidgets

Brian Vanderburg II BrianVanderburg2 at aim.com
Fri Jan 4 22:33:27 PST 2008


After some review and testing of code relating to some previous 
questions about client-observer modal, I found this library called sigc++.

Has anyone used this library for such purposes, an if so, with wxMSW?  
It seems to have some association in the tutorials with gtkmm  Also, 
would this be a good solution to the previous problems (objects such as 
window automatically being notified of important changes by registering 
to know them), maybe something like this, not sure if it is right still 
reading the manual/tutorials:

class MyFrame : public wxFrame, public sigc::trackable
{
public:

    void OnOptionsChanged();

    void Register()
    {
       m_connecton = 
theOptions.sig_opt_changed.connect(sigc::mem_fun(this, 
MyFrame::OnSomethingHappened));
    }
}

class Options
{
public:
    void Notify() { sig_opt_changed.emit(); }

    sigc::signal<void> sig_opt_changed;
}

Also, if this is a decent solution, does the auto-disconnect work both 
ways.  If the frame dies, it will disconnect from the signal in the 
options, but if the options die first, will it still work okay? Has 
anyone done something like this with sigc++?  Also, could I make the 
Register in the options instead, but still be type checked correctly:

class Options
{
public:
    template <typename X, typename Y> Register(obj, fn)
    {
       sig_opt_changed.connect(sigc::mem_fun(obj, fn))
    }
}

And call it as Register(this, MyFrame::OnOptionsChanged)

Brian Vanderburg II




More information about the wx-users mailing list