Qt State Machine.에 문제가 있습니다. 상태를 실행할 수 없기 때문에 여러 가지 오류가 발생합니다. 문제. 오류 및 오류 코드에 대한 자세한 정보는 아래를 참조하십시오.상태를 시작할 수없고 상태 간 전환 : 다양한 오류가 발생합니다.
이 내 주요 기능입니다 :
int main(int argc, char *argv[])
{
// Initialize the app
// ... app initialization here
QApplication app(argc, argv);
// Create the state machine
QStateMachine machine;
MyState* ms1 = new MyState("ms1");
MyState* ms2 = new MyState("ms2");
QFinalState* fs = new QFinalState();
ms1->addTransition(ms2);
ms2->addTransition(fs);
machine.addState(ms1);
machine.addState(ms2);
machine.addState(fs);
machine.setInitialState(ms1);
QObject::connect(&machine, SIGNAL(finished()), new Finisher(), SLOT(OnFinished()));
machine.start();
return app.exec();
}
내가 MyState
에 중단 점 설정,하지만 (실제로 단지 start
호출 할 것으로 예상) 브레이크 포인트 타격 만나지과 start
/stop
방법이 실행되지 않습니다. 응용 프로그램은 Finisher::OnFinished
메서드로 바로 이동합니다.
class MyState: public QState
{
Q_OBJECT
private:
QString _stateName;
public:
MyState(QString stateName, QState * parent = 0):QState(parent), _stateName(stateName){}
~MyState(){}
public slots:
void start()
{
qDebug() << _stateName << " start.";
emit finished();
}
void stop()
{
qDebug() << _stateName << " stop.";
}
signals:
void finished();
//void exited();
};
마무리 장치는 매우 간단하다 : 여기
내 상태 클래스입니다 내가 직접 각 상태의 부모를 설정하는 등 여러 가지를 시도했습니다class Finisher:public QObject
{
Q_OBJECT
public slots:
void OnFinished()
{
qDebug() << "Finished!";
QTimer::singleShot(0, QApplication::instance(), SLOT(quit()));
}
};
:
// If I use the following code, I get an error
// stating that "the state has already been added to this machine"
MyState* ms1 = new MyState("ms1");
MyState* ms2 = new MyState("ms2", ms1);
QFinalState* fs = new QFinalState(ms2);
ms1->addTransition(ms2);
ms2->addTransition(fs);
machine.addState(ms1);
machine.addState(ms2);
machine.addState(fs);
machine.setInitialState(ms1);
// .. and so on
그러나 machine.addState
이있는 상태를 추가 할 수없는 것으로 보이는 경우 전화 :
QStateMachine::addState: state has already been added to this machine
QStateMachine::addState: state has already been added to this machine
Unrecoverable error detected in running state machine: Missing initial state in
compound state ''
I했습니다도 그냥 생성자를 떠나 machine.addState
를 호출하지하려고 :
QState::setInitialState: state 0xa05e5e0 is not a child of this state (0x43fe94)
QStateMachine::start: No initial state set for machine. Refusing to start.
마지막에게 :
QStateMachine machine;
MyState* ms1 = new MyState("ms1");
MyState* ms2 = new MyState("ms2", ms1);
QFinalState* fs = new QFinalState(ms2);
ms1->addTransition(ms2);
ms2->addTransition(fs);
machine.setInitialState(ms1);
// .. and so on
그러나이 경우 나는 다음과 같은 오류를 얻을 수 내가 명시 적으로 초기 상태를 ms1
으로 명시하고 나서 start
이라고 부르기 때문에 이상한 점이있어서 거기에 어떤 문제가 있는지 알지 못합니다. 이 예제가 어떻게 작동하는지에 대한 아이디어가 있습니까?
전환을 추가하기 전에 상태를 상태 시스템에 추가해 보았습니까? – Jay