简体   繁体   English

QStateMachine get事件导致状态转换

[英]QStateMachine get event causing state transition

I have created a QStateMachine and I have to get the Event which has caused a transition of the state. 我创建了一个QStateMachine,并且我必须获取导致状态转换的事件。 Isn't there any opportunity to get inside my slot EnterStateInit() the signal which caused this call. 没有任何机会将引起此调用的信号放入我的EnterStateInit()插槽中。 Here my sample code: 这是我的示例代码:

CreateStateMachine()
{
    QState *Init = new QState();
    QState *CheckPrecondition = new QState();
    QState *DoWork = new QState();

    Init->addTransition(this, SIGNAL(EventStart()), CheckPrecondition);
    CheckPrecondition->addTransition(this, SIGNAL(EventSuccesfulCondition()), DoWork);
    CheckPrecondition->addTransition(this, SIGNAL(EventNotSuccesfulCondition()), Init);
    DoWork->addTransition(this, SIGNAL(EventWorkDone()), Init);
    DoWork->addTransition(this, SIGNAL(EventError()), Init);

    connect(Init, SIGNAL(entered()), this, SLOT(EnterStateInit()));
    connect(CheckPrecondition, SIGNAL(entered()), this, SLOT(CheckPrecondition()));
    connect(DoWork, SIGNAL(entered()), this, SLOT(DoWork()));

    connect(Init, SIGNAL(exited()), this, SLOT(LeaveStateInit()));
    connect(CheckPrecondition, SIGNAL(exited()), this, SLOT(LeaveStateCheckPrecondition()));
    connect(DoWork, SIGNAL(exited()), this, SLOT(LeaveDoWork()));

    mModuleStateMachine.addState(Init);
    mModuleStateMachine.addState(CheckPrecondition);
    mModuleStateMachine.addState(DoWork);

    mModuleStateMachine.start();
}

EnterStateInit()
{
  /* Get Event which caused this SLOT to react */
  SetStatus();
}

A QState is-a QObject . 一个QState是-A QObject You're free to reimplement its event() method :) To get an idea of what's going on: 您可以自由地重新实现其event()方法:)了解发生的情况:

void MyState::event(QEvent * event) {
  qDebug() << event;
  QState::event(event);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM