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,
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,