 Let's take a look at the queue final state. What we're going to do is create a non-looping state, meaning something that has a beginning and something that has an end. Our last example, we had this nice loop and it just kept going and going. We're going to take this arrow out of here. So we're going to have about 10 states and then something called a queue final state. You may be asking yourself, why do you need a queue final state? Well, that's a very good question. If you dive into the documentation it gets a little bit confusing and they point you right back to queue state and it says the signal is emitted when a final child state has entered. Meaning, it points you right back to queue final state and it just goes back and forth and you're trying to figure out what really the difference here is. Really what you need to understand is that when queue final state is entered it emits a special signal letting the state machine framework know we are now done. Stop running. That's really what it does. Super confusing the way they did that and you know how the queue final state inherits queue abstract state, not queue state. Frustrating. All right. Same interface as last time, but now we're going to do a linear state instead of a looping state. We are going to just to save a bit of time, do some copy and paste action on some of the more simple code. Queue dialog, queue state machine, queue state, queue debug, queue final state, queue abstract state and message box. So the premise here being when we run this we're going to click this and it's going to go through all the states and display them here. And when we're done it's going to say complete, disable this button and pop up in a message box so that we know beyond the shadow of a doubt we are done with our state machine. So we're going to have some slots and then I'm going to have in some private stuff here. So I'm going to have the queue state machine. I'm going to have a queue list of queue abstract states called states and a function called add state. So let's right click and I am I want a special note here kind of doing this the hard way just to really illustrate what's going on and I'm going to try to explain the hard and the easy way. So first things first we need to actually create some states to do that we want our little add state. So I'm going to go in here right click and let's go add definition add state. It's sole purpose for being is you guessed it we are going to add some states to that queue list. So just some boilerplate code. Nothing super complicated. It looks like a big old wad of code. Let's walk through it. We're just going to say add a state. We're going to assign a property and whenever you see the assign property think we are changing something. So we're going to change the line edits text to whatever the state's object name is. So it's going to be like state 0123456 blah blah blah and then I is the state's length if we're greater than zero meaning we're not the first state list. Then we want to add a transition because we're going to have a starting point the zero index. We want to transition to the next and the next and the next. Then we just simply have our state entered state exit and state finished. Notice we're doing this on the queue state not the queue final state. When this transitions from the last queue state in this list to the queue final state this queue state is going to you guessed it emit the state finished. States append and then state machine add state. Some of the stuff I'm just kind of like mind boggled here on how all of this works because you got to really kind of fish through the documentation to really figure it out. Let's go back up to our constructor here and here is where we're going to just add in some boilerplate nonsense bang. So 0 to 10 I increment we're going to create a state we're going to set that object name and we're going to call that add state which just literally does all the connections adds it to our state machine and our list. Special note here states are actually children. This is what I mean by hard way and easy way the easy way would just be the M state machine dot children but I really wanted to separate the two so you understand what's going on under the hood here. You really don't need this queue list you very easily could put this into the M state machine children. It does actually do it automatically. So for example, you can say bang the states are added as children. Let's test that out say run and we have 10 children. So all those states are nice and neat right in there. Let's go down to our dialogue. Whoops got the wrong one. There's our deconstructor for a dialogue here and all we're doing is doing our memory management. If we just backbone off the state machine children we really wouldn't need to do this again. I'm just holding it out there so you can see what's going on under the hood and let's go ahead and add our final state. This is where my slowdown just a little bit. So I'm going to say queue final state and this is going to be new queue final state again. Billions of different ways we can manage that memory if we really felt like it. I'm going to say queue state and let's call this P for pointer and let's go ahead and say queue object cast. And we're just going to grab the last state out of that list here and I'm going to say again could have used the state machine children. All right now what we're going to do is we're going to add a transition. So we're going to say P transition. Remember when we talk about a transition we're talking about moving from one state to the next. So I'm going to say UI push button and we're going to monitor that queue push button clicked. And we're going to move this over to the final or the queue final state which is going to kick off that state machine has now finished. So what I'm going to do is you guessed it. We're going to go ahead and we're going to say connect the M state machine and we want the queue state machines finished signal. Notice how we're monitoring the state machine not the queue final state and let's go ahead and say state finished. This is where it gets super super confusing. It's hard to keep track of what's actually going on here. So when the queue final state is entered it's going to emit a signal that the state machine has connected to the state machine then turns around and it admits its own finished signal. Super super confusing the way it does that. All right so let's go and state machine and let's go ahead and add our state final again because it has just got the children. It's just a queue list of pointers to queue objects so it doesn't really matter. We could have put a check box or whatever we wanted in there and that's why I really didn't use the children in case somebody tries to add something in you will very easily break your application. And then state machine set the initial state and we're going to say M states at zero. So our first state is going to be our initial state shocking I know. And then let's go ahead and go state machine. Let's go ahead and start this thing up. We need like some sound effect like a chainsaw starting up or something. All right almost done. We just need to know what exactly is going on here. I wanted to make special note of this right here. This on push button click is really our trigger for everything going on. If we don't have this in like if this didn't exist and we got this by going into the UI right click go to slot and click if we didn't do that. There is a high chance that this will never fire off because it just simply does not exist and it's just never admitted. It's one of those weird little gotchas with widgets. So if you're trying to do this on your own and you're not telling the code from GitHub and you skip that step it will just never fire off. All right. Now I've got state entered state exited bang bang entered exit very very simple. When our state finished is fired off and I could have said state machine finished that way it was a little clearer. We'll say Q info whatever the sender finished and then we're going to set the text of the line edit to complete. Set the push button enable defaults and then display a message box to the user because you know how users are they can get a little fickle and you got to tell them 30 or 40 times. Save and run. Let's check this out. State zero is our initial state and we're just going to blast through these here 1 2 3 4 5 6 7 8 9 and bang state machine is finished. Everything works as expected. So if we dive in here we can see how the signals and slots worked under the hood. We have just kind of started off with 10 children and then bang bang bang. We've done all our entered exits from our various states and then the state machine emits the finished signal. Very confusing the way they did that. Just understand that if you want a linear state or some sort of final state you need to use the Q final state class. But you don't monitor this class you monitor the Q state machine.