[Qt-interest] Using QStateMachine in large apps (Was qscxml and Qhttp)
Stephen Kelly
steveire at gmail.com
Fri Oct 22 01:59:57 CEST 2010
noam.rosenthal at nokia.com wrote:
> Actually, the problem is the build order
> You have to make install scc before you can compile the examples under
> examples/scc. That's because the stuff under examples/scc requires scc.prf
> to be installed in [QTDIR]/mkspecs/features.
>
> So:
>
> cd scc
> [QTDIR]/bin/qmake
> make install
>
> cd ..
> make
Thanks for that. I managed to build the module and build and try the
examples. They seem to work well. I tried make docs, but that didn't work,
so I tried cd doc && qdoc scxml.qocconf, which also did nothing useful (I
don't really know how to use qdoc), so I just read the doc source.
I'm new to QStateMachine and am planning to use it in kontact-mobile and
another large project. I just read through the docs a couple of days ago. I
was wondering if there was a better way to maintain the state machine than
in C++ code. I thought at first that qscxml would be the answer, and it
might be. Maybe you can clarify. It seems to aimed towards implementing the
state machine in xml+QtScript.
My aim is to implement my own transition class so that I can change states
based on selections in a QItemSelectionModel. Such a thing would be defined
in a header file which could be specified in a similar way to how they are
specified in .ui files.
Given that, I'd do something like this (and I know it's not valid scxml :)):
<statemachine>
<state id="no selection"
object="myObject"
property="something"
value="9" />
<state id="single selection"
object="myObject"
property="something"
value="42" />
<transition type="ModelSelectionTransition"
definition="modelselectiontranstion.h"
from="no selection"
to="single selection">
<property name="mode" value="SingleSel" />
</transition>
</statemachine>
the ModelSelectionTransition class would set up the connection to the
selectionChanged signal and would implement the logic of whether to run the
transition for a particular value in the selectionChanged.
So the above would generate code something like this:
QObject *myObject = getSomeObject();
myObject->setObjectName("myObject");
QStateMachine machine;
QState *noSel = new QState();
noSel->assignProperty(myObject, "something", 9);
QState *singleSel = new QState();
singleSel->assignProperty(myObject, "something", 42);
ModelSelectionTransition *tr = new ModelSelectionTransition(SingleSel);
tr->setTargetState(singleSel);
noSel->addTransition(tr);
where ModelSelectionTransition is something like
class ModelSelectionTransition
{
bool eventTest(QEvent *e)
{
if (m_type == SingleSel)
// if the selection model has only one item, accept it.
if (m_type == MultiSel)
// ...
}
};
The engine for the scxml description would need to have a Context to inject
the myObject into it etc. It looks like QScxml::registerObject does exactly
that. What is the RightWay to use qscxml to what I'm trying to achieve?
Sorry for the brain-dump post. I haven't written any code for this yet, only
read documentation so far. Hope I got it right.
All the best,
Steve.
More information about the Qt-interest-old
mailing list