Transit 10 functions in sequence based on a timer using State Machine Framework



  • I created a sequence of 10 function
    functionA, functionB, functionC, functionD ...
    that i would like to transit sequencely based on a timer.

    I do not know how to join them together using State machine framework.
    I did many hours of reading and i still don't understand how to link them together. Please kindly help.



  • //Code i wrote myself, please kindly comment and assist.

    @
    QStateMachine machine;
    QState *group=new QState();
    group->setObjectName("group");
    QTimer timer;
    timer.setInterval(1250);
    timer.setSingleShot(true);
    connect(group,SIGNAL(entered()),&timer,SLOT(start());

    //start at state level
    QState *state1= new Qstate(function1);
    QState *state2= new Qstate(function2);
    QState *state3= new Qstate(function3);
    QState *state4= new Qstate(function4);
    group->setInitialState(state1);

    s2->addTransition(function1,SIGNAL(timeout),function2);
    s3->addTransition(function2,SIGNAL(timeout),function3);
    s4->addTransition(function3,SIGNAL(timeout),function4);

    //end at machine level
    machine.addstate(state1);
    machine.addstate(state2);
    machine.addstate(state3);
    machine.addstate(state4);

    machine.addState(group)
    machine.setInitialState(group);
    machine.start();
    @

    [edit: added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    Hi,

    What are function1 and friends ?



  • I like to transit sequentially from function1 to function10. The state Machine framework that i wrote, why is it not correct?


  • Lifetime Qt Champion

    I understood why you wanted to do, however you didn't answer my question

    @QState *state1= new Qstate(function1); << what is function1 ?@



  • function1 is 1st LED blinking
    function2 is 2rd LED blinking.
    function3 is 3 rd LED blinking.



  • i understand. Problem solved


  • Lifetime Qt Champion

    So, what was the problem ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.