PDA

View Full Version : Guarded transition depending on an object (not a type)



ClintEastwood
28th August 2013, 12:04
Hello all,

I'm trying to implement a Guarded Transition for a QStateMachine following this example:


class CheckedTransition : public QSignalTransition
{
public:
CheckedTransition(QCheckBox *check)
: QSignalTransition(check, SIGNAL(stateChanged(int))) {}
protected:
bool eventTest(QEvent *e) {
if (!QSignalTransition::eventTest(e))
return false;
QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(e);
return (se->arguments().at(0).toInt() == Qt::Checked);
}
};

...

QCheckBox *check = new QCheckBox();
check->setTristate(true);

QState *s1 = new QState();
QState *s2 = new QState();
CheckedTransition *t1 = new CheckedTransition(check);
t1->setTargetState(s2);
s1->addTransition(t1);



However, in my case, instead of the signal stateChanged(int) with only an int argument, I have a signal with two arguments: an object and an enum type, and depending on the state of the object the eventTest will return true or false. This is my signal:



void newMessage(Message, System);


System is an enum type so I can access it as if it were an int value, but Message is a class... and I do not know how to access to this argument through the SignalEvent instance. So, my problem is exactly in this expression:



se->arguments().at(0).toInt()


I have tried to cast the QVariant object to a Message instance but it generated an error. Does anyone know any solution? Is it possible to do what I want?

Thanks in advance,

wysota
3rd September 2013, 22:06
Does Message inherit QObject? Is it registered with QVariant?

ClintEastwood
4th September 2013, 08:52
No, Message does not inherit QObject neither it is registered with QVariant. Do I have to do these things to achieve what I want? Can you outline me a little more those two points?

Thanks,

wysota
4th September 2013, 09:31
If you want to get this kind of object as a stored argument then it has to be registered with QVariant.