 Hey everybody, it's Brian and welcome to the 33rd Qt tutorial with C++ and GUI programming. I'm going to continue our topic of threading and rather than having you sit here and watch me type a bunch of code, I wanted to have some already written because we've gone over this. Alright, we've just got our main file and we have created a thread, or I should say we've created a subclass of Qthread. Some have argued that this is not the correct way of doing this and I've been reading up on the correct way of doing it and we'll be covering that soon. Interestingly though, this is the correct way of doing it according to Qth's own documentation and three books that I've read. So it's kind of interesting to see the disparity between the different parties where some saying you subclass, some saying you don't subclass and I'm trying to really understand the differences between the two. But that, anyways, sorry, it's outside the scope of this tutorial. What we're going to try to do today is launch a thread and it's just a very simple, you know, for int i equals 0 to 1000 and it's just going to print it out. But we want to know when this thread ends. We want to actually wait for it to end and then do something. I mean, if we just save and run it now, it just goes to 1000 and we have no idea when it actually ends. So what you do here is you say mthread wait and what what does is it creates a wait condition where you literally sit and wait for that thread to complete. And then when you're done, you can actually just include, let's include QtBug there. That way we can just print something out QtBug and we will say done just so that we can see that we are in fact waited for that thread to complete. Save and run. And when you run it, you notice how it goes all the way up to 999 and then says done. Well, that would buy pretty quick. So let's actually put a sleep in there just so we can see this this thing hard at work here. And we'll say no second sleep and let's just say 100 and we don't want to sit here all day. Let's actually kick this down to 10 and I better actually increase that a little more because I'm going to have to drag the window out. So what this is going to do is count from zero to nine and it's going to sleep half a second in between each time and at the end it's going to say done. This would be useful say if you want to copy a file or something and then once the file is done, you want to continue doing something else. So let's compile and run and we'll just see it count down. And once the thread is done, it says done. So pretty simple stuff. You should note however though that while you are waiting for that thread, nothing else happens. So if you, you know, some code here, it's not going to execute because this thread, this current thread is in a wait condition. It's waiting for this thread right here to finish. So that's a pitfall that I've fallen into once before. So if you make that mistake, don't sweat it. We all do it. This is Brian. Thank you for watching. I hope you found this video educational and entertaining.