dyngoman
15th March 2010, 07:42
The State Machine framework seems very interesting to me since i work on projects that require state devices modeling and graphical interfacing.
I am new to Qt and the tutorials and examples seemed to be logic and straight forward but still i could not get the my state machine learning example to work.
Here's what I did:
-started a new Qt GUI project (using QtCreator) , named my class Dialog and inherited the QDialog.
-added some buttons and a text area.
-added a state machine and some states.
-connected signals and slots.
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
m =new QStateMachine(this);
s1 = new QState();
t1 = new QTimer(s1);
t1->setInterval(3000);
t1->setSingleShot(true);
connect(s1,SIGNAL(entered()),t1,SLOT(start()));
connect(s1,SIGNAL(entered()),this,SLOT(WriteTextA( )));
s1->addTransition(t1,SIGNAL(timeout()),s2);
s2 = new QState();
t2 = new QTimer(s2);
t2->setInterval(3000);
t2->setSingleShot(true);
connect(s2,SIGNAL(entered()),t2,SLOT(start()));
connect(s2,SIGNAL(entered()),this,SLOT(WriteTextB( )));
s2->addTransition(t2,SIGNAL(timeout()),s3);
s3 = new QState();
t3 = new QTimer(s3);
t3->setInterval(3000);
t3->setSingleShot(true);
connect(s3,SIGNAL(entered()),t3,SLOT(start()));
connect(s3,SIGNAL(entered()),this,SLOT(WriteTextC( )));
s3->addTransition(t3,SIGNAL(timeout()),s1);
connect(this->ui->btnA,SIGNAL(clicked()),this,SLOT(WriteTextA()));
connect(this->ui->btnB,SIGNAL(clicked()),this,SLOT(WriteTextB()));
connect(this->ui->btnC,SIGNAL(clicked()),this,SLOT(WriteTextC()));
m->addState(s1);
m->addState(s2);
m->addState(s3);
m->setInitialState(s1);
m->start();
}
void Dialog::WriteTextA()
{
this->ui->textEdit->append("ACTION::A");
}
....
When I build and Run it exits with a random exit code.
Where did I go wrong?
I am new to Qt and the tutorials and examples seemed to be logic and straight forward but still i could not get the my state machine learning example to work.
Here's what I did:
-started a new Qt GUI project (using QtCreator) , named my class Dialog and inherited the QDialog.
-added some buttons and a text area.
-added a state machine and some states.
-connected signals and slots.
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
m =new QStateMachine(this);
s1 = new QState();
t1 = new QTimer(s1);
t1->setInterval(3000);
t1->setSingleShot(true);
connect(s1,SIGNAL(entered()),t1,SLOT(start()));
connect(s1,SIGNAL(entered()),this,SLOT(WriteTextA( )));
s1->addTransition(t1,SIGNAL(timeout()),s2);
s2 = new QState();
t2 = new QTimer(s2);
t2->setInterval(3000);
t2->setSingleShot(true);
connect(s2,SIGNAL(entered()),t2,SLOT(start()));
connect(s2,SIGNAL(entered()),this,SLOT(WriteTextB( )));
s2->addTransition(t2,SIGNAL(timeout()),s3);
s3 = new QState();
t3 = new QTimer(s3);
t3->setInterval(3000);
t3->setSingleShot(true);
connect(s3,SIGNAL(entered()),t3,SLOT(start()));
connect(s3,SIGNAL(entered()),this,SLOT(WriteTextC( )));
s3->addTransition(t3,SIGNAL(timeout()),s1);
connect(this->ui->btnA,SIGNAL(clicked()),this,SLOT(WriteTextA()));
connect(this->ui->btnB,SIGNAL(clicked()),this,SLOT(WriteTextB()));
connect(this->ui->btnC,SIGNAL(clicked()),this,SLOT(WriteTextC()));
m->addState(s1);
m->addState(s2);
m->addState(s3);
m->setInitialState(s1);
m->start();
}
void Dialog::WriteTextA()
{
this->ui->textEdit->append("ACTION::A");
}
....
When I build and Run it exits with a random exit code.
Where did I go wrong?