[Qt-interest] QStateMachine: There are no signals signaling adding and removing of a state
Sean Harmer
sean.harmer at maps-technology.com
Tue Aug 4 16:29:17 CEST 2009
Hi,
On Tuesday 04 Aug 2009 14:46:39 Oliver.Knoll at comit.ch wrote:
> Piotr Dobrogost wrote on Tuesday, August 04, 2009 3:28 PM:
> > ...
> > To do this I need a signal signaling adding new states to the
> > QStateMachine but don't see anything like this.
> >
> > Any ideas?
>
> What about introducing a "StateMachineManager", something like:
>
> class StateMachineManager : public QObject {
> Q_OBJECT
> public:
> // c'tor
> StateMachineManager(StateMachineHandler &stateMachineHandler);
> ...
> void addState(QState *state);
> private:
> QStateMachine m_stateMachine; // HAS-A
> StateMachineHandler &m_stateMachineHandler;
> };
>
> void StateMachineManager::addState(QState *state) {
> m_stateMachine.add(state);
> connect(state, SIGNAL(entered()),
> &m_stateMachineHandler, SLOT(handleEntered()));
> }
>
> Cheers, Oliver
Another option is to derive your own states from QState and reimplement the
onEntry() virtual function. Granted, this may not fit in with the rest of your
scheme in this case though.
Another option is to derive a class from QStateMachine and override the
addState() method to emit a stateAdded( QState* ) signal for e.g.
HTH,
Sean
More information about the Qt-interest-old
mailing list