简体   繁体   English

如何检测被忽略/拒绝的QEvent发布到QStateMachine

[英]How can I detect ignored/rejected posted QEvent to QStateMachine

I need to see if a custom posted event to the state machine was accepted or not. 我需要查看是否已接受向状态机发布的自定义事件。 My approach is to subclass QStateMachine. 我的方法是继承QStateMachine。 See http://doc.qt.nokia.com/latest/statemachine-api.html section Events, Transitions and Guards 请参阅http://doc.qt.nokia.com/latest/statemachine-api.html部分事件,过渡和防护

I'm wondering is there is not something I missed in the code below. 我想知道下面的代码中没有我想念的东西。 Is there not another/better approach? 没有其他/更好的方法吗?

Basically here is the same as per the Qt Doc: 基本上,这里与Qt文档相同:

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;
}

And the simplest way I could find to far to detect the reject is this: 我可以找到的最简单的方法来检测拒绝是:

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); 

}

好的,终于回答了我自己的问题:它可以工作,但是由于没有正式记录,因此基本上是黑客

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

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