0

I'm using signals2. I'm trying to setup a viewstate/view relationship with a view having a subscribed slot. I can't seem to trigger the handler function though. Is there something wrong with the binding? I'm new to c++ so maybe there's a misuse of const/reference/dereferencer.

In My State Machine:

void State::setAppState( State::AppState pNewState )
{
    mCurrentState = pNewState;
    // this prints fine
    ci::app::console() <<"\nState::setState " << pNewState << "\n";
    (*mSignal)();
}

In my view base class:

BaseView::BaseView( State& pState ): mState(pState)
{
    // register connection to state
    mConnection = mState.connect(boost::bind(&BaseView::stateChange, this));
}

// the use of const is right from their example in the doc.
// but i found i had to const_cast to get it to compile
// can i get rid of the 'this' and do it without const method? 
// edit: no (boost compile errors)
void BaseView::stateChange()  const
{
    int s = const_cast<State&>(mState).getAppState();
    // this does not print
    ci::app::console() << "\n>>>>> View Slot registered change " << s << "\n" ;
}

In my view subclass:

AttractView::AttractView(State pState):BaseView(pState)
{
     // to pass the constructor param
}

Main App:

mAttract = AttractView( mStateMachine );
mStateMachine.setAppState(State::AppState::Attract); //AppState is just an enum
FlavorScape
  • 13,301
  • 12
  • 75
  • 117

1 Answers1

0

I think the problem was actually with the initializer list.

While pState was a valid in the BasiView constructor, it did not bind properly, or it was bound before signals initialized and the binding was erased.

 BaseView::BaseView( State& pState ): mState(pState)

Adding an additional init/create function clears this up.

void BaseView::init(State& pState){
    mConnection = mState.connect( (boost::bind(&BaseView::stateChange, this)) );
}

...

mAttract.init( mStateMachine );
mStateMachine.setAppState(State::AppState::Attract);
FlavorScape
  • 13,301
  • 12
  • 75
  • 117