gpt4 book ai didi

c++ - QStateMachine 获取导致状态转换的事件

转载 作者:行者123 更新时间:2023-11-28 05:31:11 25 4
gpt4 key购买 nike

我已经创建了一个 QStateMachine,我必须获取导致状态转换的事件。难道没有任何机会进入我的插槽 EnterStateInit() 导致此调用的信号。这是我的示例代码:

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

最佳答案

QState 是一个QObject。您可以自由地重新实现它的 event() 方法 :) 要了解发生了什么:

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

关于c++ - QStateMachine 获取导致状态转换的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39490731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com