Results 1 to 3 of 3

Thread: QtStateMachine in GUI projects

  1. #1
    Join Date
    Feb 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QtStateMachine in GUI projects

    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.

    Qt Code:
    1. Dialog::Dialog(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Dialog)
    4. {
    5. ui->setupUi(this);
    6. m =new QStateMachine(this);
    7.  
    8. s1 = new QState();
    9. t1 = new QTimer(s1);
    10. t1->setInterval(3000);
    11. t1->setSingleShot(true);
    12. connect(s1,SIGNAL(entered()),t1,SLOT(start()));
    13. connect(s1,SIGNAL(entered()),this,SLOT(WriteTextA()));
    14. s1->addTransition(t1,SIGNAL(timeout()),s2);
    15.  
    16. s2 = new QState();
    17. t2 = new QTimer(s2);
    18. t2->setInterval(3000);
    19. t2->setSingleShot(true);
    20. connect(s2,SIGNAL(entered()),t2,SLOT(start()));
    21. connect(s2,SIGNAL(entered()),this,SLOT(WriteTextB()));
    22. s2->addTransition(t2,SIGNAL(timeout()),s3);
    23.  
    24. s3 = new QState();
    25. t3 = new QTimer(s3);
    26. t3->setInterval(3000);
    27. t3->setSingleShot(true);
    28. connect(s3,SIGNAL(entered()),t3,SLOT(start()));
    29. connect(s3,SIGNAL(entered()),this,SLOT(WriteTextC()));
    30. s3->addTransition(t3,SIGNAL(timeout()),s1);
    31.  
    32. connect(this->ui->btnA,SIGNAL(clicked()),this,SLOT(WriteTextA()));
    33. connect(this->ui->btnB,SIGNAL(clicked()),this,SLOT(WriteTextB()));
    34. connect(this->ui->btnC,SIGNAL(clicked()),this,SLOT(WriteTextC()));
    35.  
    36. m->addState(s1);
    37. m->addState(s2);
    38. m->addState(s3);
    39.  
    40. m->setInitialState(s1);
    41. m->start();
    42. }
    43.  
    44. void Dialog::WriteTextA()
    45. {
    46. this->ui->textEdit->append("ACTION::A");
    47. }
    48.  
    49. ....
    To copy to clipboard, switch view to plain text mode 

    When I build and Run it exits with a random exit code.
    Where did I go wrong?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtStateMachine in GUI projects

    In lines 14 and 22 s2 and s3 are not initialised.

  3. #3
    Join Date
    Feb 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtStateMachine in GUI projects

    Wow, that was a rookie mistake...adding a transition to a pointer that was not initialized.
    Thanks a lot!

Similar Threads

  1. QMake for non-qt projects
    By rubenvb in forum Installation and Deployment
    Replies: 3
    Last Post: 25th October 2009, 13:21
  2. new projects ???
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2009, 10:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.