4.6最新加入QStateMachine

 

4.6最新加入QStateMachine

今天在使用该类的时候,出现了一些从来没遇到过的问题,程序在执行a.exec()方法时挂掉了,觉得应该和该类的实现机制有关,所以决定首先对该类探个究竟。

QStateMachine类在corelib/statemachine中,继承自QState类,通过跟踪发现,最早的类是对QState类的一个抽象接口——QAbstractState类。整个QStateMachine的机制在QtThe State Machine Framework文章中进行介绍。

在刚才无意间的操作中,发现最新的QtCreater已经可以完成对Qt源代码的编译,这样一来,以后再做分析和调试的时候,就更加方便了。

QStateMachine的设计应该来源于有限状态机的概念,主要提供对程序运行过程中不同状态间切换的管理工作。

Classes in the State Machine Framework

These classes are provided by qt for creating event-driven state machines.

QAbstractState

The base class of states of a QStateMachine

QAbstractTransition

The base class of transitions between QAbstractState objects

QEventTransition

QObject-specific transition for Qt events

QFinalState

Final state

QHistoryState

Means of returning to a previously active substate

QKeyEventTransition

Transition for key events

QMouseEventTransition

Transition for mouse events

QSignalTransition

Transition based on a Qt signal

QState

General-purpose state for QStateMachine

QStateMachine

Hierarchical finite state machine

QStateMachine::SignalEvent

Represents a Qt signal event

QStateMachine::WrappedEvent

Holds a clone of an event associated with a QObject

上面这些就是整个模块所包含的类了,我们现在对这些类间的继承关系进行分析。

上面的三个图,表示了该体系的整体继承关系。可以看出来,主要分为三部分,分别是负责存储状态的QAbstractState接口,负责对信号进行处理的QAbstractTransition接口,以及为状态机类提供信号事件的QEvent接口。

Let’s look at the detail description. We can see the QStateMachine class was designed by the thinking of finite state machine. Look,

The QStateMachine class provides a hierarchical finite state machine.

QStateMachine is based on the concepts and notation of Statecharts. QStateMachine is part of The State Machine Framework.

The QStateMachine is a manager of a set of QState. We should attention to set the initial state.

void QStateMachine::addState(QAbstractState *state)

{

    if (!state) {

        qWarning("QStateMachine::addState: cannot add null state");

        return;

    }

    if (QAbstractStatePrivate::get(state)->machine() == this) {

        qWarning("QStateMachine::addState: state has already been added to this machine");

        return;

    }

    state->setParent(this);

}

We always use the addState() function from QStateMachine class. Let’s begin from this.

void QStateMachine::addState(QAbstractState *state)

{

    if (!state) {

        qWarning("QStateMachine::addState: cannot add null state");

        return;

    }

    if (QAbstractStatePrivate::get(state)->machine() == this) {

        qWarning("QStateMachine::addState: state has already been added to this machine");

        return;

    }

    state->setParent(this);

}

In fact, the only thing this function does is to set the object to the Object Tree. Perhaps we don’t need to use this function. Let me have a try.

That’s right. It isn’t necessary to use the addState() function to make the state machine work. The only thing must be to set the initial state.

It’s time to go to sleep. The next day, I will do a detail analyze on the state machine module.

 

2009/11/5 11:05

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值