Removing transitions from a QState causes crash



  • Hi,

    I add two transitions to the state and build up a list of states thus:

    @ Transitions.append(WelcomeState->addTransition(HelpSignalMapper, SIGNAL(mapped(QString)), HelpState));
    Transitions.append(WelcomeState->addTransition(GuiSignalMapper, SIGNAL(mapped(QString)), BasicProdState));
    @

    This works and on running the code, the transitions occur.
    Later I want to remove the states but all attempts cause the application to crash, not at the point I remove the transitions but a couple of lines later. (If I comment out the code removing the states then the rest of the application continues to run ok)

    I have tried two methods to remove the transitions but the result is the same:

    Either using the list I built up myself:

    @ while (!Transitions.isEmpty()) {
    WelcomeState->removeTransition(Transitions.takeFirst());
    }@

    Or using the transitions() method to gain the list of transitions:

    @ QList<QAbstractTransition*> transitions = WelcomeState->transitions();
    while (!transitions.isEmpty()) {
    WelcomeState->removeTransition(transitions.takeFirst());
    }@

    Any ideas as I can't see what I am doing wrong.

    Thanks



  • Have you tried to debug this code?
    Is WelcomeState still a valid pointer?



  • Have checked again just to be sure.
    WelcomeState gets a value in the constructor

    @
    WelcomeState = new QState();
    @

    and this is the same when I reach

    @
    QList<QAbstractTransition*> transitions = WelcomeState->transitions();
    @



  • Hi,

    I just checked that. For me, it works, when I do the remove-thing in the state you are reaching.

    For example, when you have 3 transitions in state A and you go from state A to state B, you can remove the transitions from state A in state B.

    Hope it helps.


Log in to reply
 

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