[Qt-interest] was event accepted by state machine?
K. Frank
kfrank29.c at gmail.com
Tue Feb 1 15:48:04 CET 2011
Hello Max!
On Tue, Feb 1, 2011 at 7:48 AM, Maxim Kirillov <max630 at gmail.com> wrote:
> Hello
>
> Let's say I have a QStateMachine. For some event there are
> states that have transition defined for that event and
> states that does not listen for that event.
>
> I would like to trigger the event and know if it was
> accepted.
Is this for debugging or diagnostic purposes?
If not for some kind of debugging, you probably don't want to do
this. The producer of the event shouldn't need to know or care
what, if anything, the state machine does with its event. That's
the concern of the state machine.
(By way of a somewhat weak analogy, let's say you have a
function that takes two arguments, and the second argument is
used only for certain values of the first argument. There is no
built-in way for the caller of this function to know whether the
second argument is used, and in general, it's not the caller's
business.)
> ...
> The only solution that comes to mind is create a fake "bad"
> state and define transition to that state for each state
> that should not react to it.
I think instead you could have the states that are supposed to
ignore the event make transitions back to themselves (rather
than to a fake "bad" state). You could have an action associated
with the transition-to-self that logs some kind of message, "event
ignored."
> But this raises a lot of
> question with keeping history and adding events for that
> state and so on.
Yes it does raise these issues. Much cleaner and less confusing
not to introduce a fake state.
> So, it would be much better to have a
> straightforward way to know is an event, signal or whatever
> is really listened for by the state machine.
Again, what is your purpose here? If it's not for diagnostics, then you
might want to change your approach, and we ought be able to help you
figure out a cleaner design.
> Max
Good luck.
K. Frank
More information about the Qt-interest-old
mailing list