我需要查看是否接受了状态机的自定义发布事件。我的方法是继承 QStateMachine。请参阅http://doc.qt.nokia.com/latest/statemachine-api.html部分事件、转换和警卫
我想知道下面的代码中是否没有遗漏什么。没有另一种/更好的方法吗?
基本上这里与 Qt Doc 相同:
bool MyStateTransition::eventTest(QEvent *e)
{
if (e->type() != QEvent::Type(QEvent::User+1)) // MyEvent
return false;
MyEvent *se = static_cast<MyEvent*>(e);
if(m_value != se->value)
{
se->setRejected(true);
return false;
}
qDebug() << "MyStateTransition::eventTest() - Transition " << m_value << " accepting event " << se->value;
se->setRejected(false);
return true;
}
到目前为止,我能找到的最简单的检测拒绝的方法是:
void MyStateMachine::endSelectTransitions(QEvent *event)
{
if (event->type() != QEvent::Type(QEvent::User+1)) return;
MyEvent *se = static_cast<MyEvent*>(event);
if(se->rejected())
emit eventRejected(se);
else
//Not really needed since we can use triggered() which will fire after
emit eventAccepted(se);
}