Nominate our 2022 Qt Champions!

Removing QStates from a QState

  • I have a need when using QStateMachine to dynamically create a number of identical substates to represent a looping action. I do this by creating a list of states and setting up their transitions when I am in the onEntry event in the QState. When I exit the state via onExit I delete the states I created. These dynamic states are transitioned to and from via permenant states in the QState

    Is this safe to do? I know QStateMachine has a removeState method, and the documentation states to try to avoid doing this while the machine is running, but is this only for top level states? Is deleting the QStates safe?

  • Lifetime Qt Champion


    Can you explain why that looping action needs these "dynamic states" ?

  • After extensive testing I discovered this is not safe. I will just use a flag to determine how many more times I need to loop through a state.

Log in to reply