我正在使用信号2。我正在尝试使用具有订阅槽的视图设置视图状态/视图关系。我似乎无法触发处理程序函数。绑定有问题吗?我是 C++ 新手,所以可能误用了 const/reference/dereferencer。
在我的状态机中:
void State::setAppState( State::AppState pNewState )
{
mCurrentState = pNewState;
// this prints fine
ci::app::console() <<"\nState::setState " << pNewState << "\n";
(*mSignal)();
}
在我看来基类:
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" ;
}
在我看来子类:
AttractView::AttractView(State pState):BaseView(pState)
{
// to pass the constructor param
}
主应用:
mAttract = AttractView( mStateMachine );
mStateMachine.setAppState(State::AppState::Attract); //AppState is just an enum