 Okay, so the last few videos we've really outlined some challenges with working with Qt and templates and specifically Qt templated classes. Now we need to actually understand that if we're going to get around that disable copy constructor in QObject by using pointers and we have to manage our own memory there is a better way and it's called a shared pointer. We've worked with this before it's super easy to use and it works beautifully with templated classes. So let's go ahead and put some includes in here. Qt about Qshared pointer in my class. My class again is just a blank class that has constructed and destroyed. So we can see actually it's full life cycle here. All right, let's jump in here and let's actually say void add items. I should say yeah add items got a little ahead of myself there. Qlist and this is where things get a little bit confusing. You notice how I'm putting those brackets in there immediately. That way I don't lose track of where I am because I'm not the best at this. And I'm going to say Qshared pointer and then put the brackets in again. You get this double arrow that confuses some people. Don't let it and my class list. So it has a very horrible looking parameter there but it's actually very very simple. We're just making a Qlist filled with Qshared pointers that uses my class. Now because we're using Qshared pointer, we're telling Qt, hey you track the memory because I'm busy and I don't want to mess around with it. Let's go ahead and grab this and then we just simply say and then we can say my class make sure that does not have a parent make it very painfully obvious that it does not have a parent. I'm going to say my class set object name and let's go ahead and give this some sort of super special snazzy name. For example my class and then whatever number we're currently on and then we're just going to list append this. Now we want to make sure we encapsulate this or wrap this inside of a Qshared pointer. So I'm going to say Qshared pointer and let's go ahead and say my class and give it our instance there my class. So really what have we done here? My gosh, what have we done? So very simple. We have a list. The list instead of pointers has Qshared pointer which wraps it around of the pointer to our class so we don't have to manage that memory. Looks really confusing if you're from newbie land but seasoned veterans especially you old C++ gurus are going to know exactly what that is. Now we can go ahead and let's just play around with this just a little bit here. So I want to say void test list. I'm just going to make a function so we can see Qt do that automatic memory management for us. We don't want to have to play around with it. Save just a moment of typing. I'm going to grab this. Say this is our list and I'm going to go ahead and say add items. Add those items in and then we're going to say list dot and I want to remove add let's say to why not. I'm going to pay something in super quick. So I'm just going to say Q info count whatever that is and then print that out again just so we can see that it was actually removed. I'm going to do a for each and this is where sometimes people get a little confused again. Super super simple. You just need the type item and then we need our container which is the list. If it seems like I'm copying and pasting a lot within my own code it is for I am for a reason and it is because you can very easily misspells something like that and then you have all sorts of weird errors I can't even say it. I have all sort of weird errors that you'll have to figure out here. So 99% of the time the IDE will catch them but once in a while you have that one where you just sit there for 10 whole minutes looking at your screen going what the hell just happened. So oops not object cast object name and then we're going to go ahead and move this down here. So really what are we doing here? We're just making our list of Qshared pointers which hold a pointer to the my class. We're going to fill that list up with 10 items and then we're going to print it out I should say print out the length. We're going to remove at 2. This is the interesting bit here. Then we're just going to print out the object name for each one print out the count and then it's going to exit and you're going to see something beautiful happen. Qshared pointer is going to come to the rescue and remove all of that memory for us. Simple to use, simple to understand and most importantly it takes us out of memory debugging. Voila. So we have a bunch of constructed count and then we removed one and then sure enough we can see it goes 0, 1, 3 because we removed that other one. We have a count of 9 because we removed it and the rest are destroyed automatically for us. So if you're ever concerned about putting a pointer in a Qlist, don't. You have plenty and plenty of tools at your disposal whether you do Qdelete all or you make it a list of Qshared pointers, it doesn't really matter either way as long as you just remember to take care of that memory. When in doubt I almost always prefer the Qshared pointer simply because I don't have to worry about forgetting to do the Qdelete all.