 Hey everybody, this is Brian, and welcome to the 106th tutorial with C++ and GUI programming. And we're just going to make a new QWidget project, and we're going to make a GUI application. And let's just put it wherever you put your stuff. And we're going to call this complete. We're going to cover completions. Completions are actually very simple and very, very cool, and I'm starting to sound like a Nokia salesperson. Some more I do these videos, but it's all good. So we've got our simple project here. We're just going to open it up, tick, tock, tick, tock. There we go. And we're going to throw some stuff on here real quick. Throw a line at it, one line at it, two, throw some labels on here. All right. And then we're going to just go like this, like this. There. So we've got our nice, neat form, and we'll say names, and we'll say files. So what we're going to do here in a nutshell is when we run this thing, we're going to type in this box, and we're going to have automatic completion for names. And if we type in this box, we'll have automatic completion for the file system. So let's just go ahead and give this a good whirl here, let it build, run. And when you see right now, nothing happens. So let's make the magic happen, as one of my co-workers says. We're going to open dialog.h, and if it's been a while since you've done a widget or a form-based application, don't worry, we're going to explain all this stuff. So first thing we need to do is our occludes. So we need to go, we'll add QCompleter, and let's also add the QDurrModel. And my daughter always giggles whenever I say DurrModel because she thinks of like a supermodel saying Durr. Anyways, stupid teenage humor. So now we're going to make two of these, one for a string list and one for a model. And if you don't know what I mean by model, go out to my YouTube videos and look up how to work with models within Qt. They're very simple, very easy to understand. So we got our string completer and QComplete, and we're going to make a pointer to our model completer. Now I should note that both of these are just QCompleter objects, or I should say pointers to QCompleter objects, but you can handle them differently. You can say give it a string, or I should say string list, or give it a model. And you'll see what I mean here in a second. Go ahead and open up dialog.cpp. And this is where we're going to actually set this up. So we'll say use the string list, QStringList. Wow, I cannot spell today. So we got our completion list. Now we want to add a few items into this list here. So we're going to say, let me just grab some names here. My name, Brian. And boy, what are some names? Spart, just making names up here. And we will say Brad. And if you've kind of noticed, I'm starting all these with the letter B. We'll say Beth. The reason why I'm doing that is because I'm doing a very simple example of how to use a string list. So when I start typing the letter B, it's going to pop up on a list. You notice how two of these start with Br, Brian and Brad. So when I type Br, the list will narrow down to just Brian and just Brad. And you'll see what I mean by that in just a second here. So stringCompleter equal new, QCompleter. I posted a video on YouTube where I'm kind of frazzled at the moment because I found out my job is being revoked or taken away. I'm not getting fired if my job's being transitioned. So I have to start job hunting if I don't get transitioned with everybody else. So I'm kind of not happy at the moment, but one day at a time. Anyway, so we're going to make a new QCompleter object and we're going to hand it a reference to the completion list or the string list and then give it this or this object. Now we want to do a little bit of extra magic here. So we'll say stringCompleter and we want to set the case sensitivity, whether it's upper or lower. And we're just going to say Qt and we're just going to say case and sensitive because we don't really care. And then now we need to bind that or set the completer. So we'll say UI, line at it because that's our first one. We're going to set completer. Save your work, run it. If you typed everything, all shall be well. Now when you start typing, we'll just type letter X, notice nothing happens. Type the letter B. Whoa, we suddenly have a list, BR, and it narrows it down. Now you can navigate through this list using the up and down arrows. And if you like what you see, you can just press tab. So let's try that again. If you don't like what you see, you just keep typing and it'll change it. Pretty neat, huh? Now we're going to make this bad boy work. This is going to be a model. And we're just going to use the file system because it's a very simple way of populating a model. Use a model. If you have gobs and gobs of data, sometimes models are actually a lot easier than string lists. I mean they're kind of complex once you start working with them, but once you get the hang of them, it's much, much easier. So we're going to make our, our completer. And we want to do set models. All right. Got kind of distracted there. And we're just going to make a new cuter, oops, sorry, cuter model to give it our model completer. I swear at these cats. I am invisible. I know you guys gripe about me complaining about these cats. I'm just, every time I start working on something, they're just all over me. And then it's pretty much the same thing. We're just going to set the completer. We're going to say model completer. That's all there is to it. So let's review real quick before we run this. The first one, we're creating a string list and populating it. Then we create our Q completer, set the case sensitivity to, you know, we don't care case and sensitive. And then we're just setting the completer on the line edit. Same thing when we want to use model. We make our new Q completer. At this time, we're seeing a new cuter model. So we're letting Qt actually generate the model for us using the file system and then handing it off into the completer and then binding that into the, whoops, the line edit right here using the set completer. So knock on wood. Let's run this. That still works. And I'm on a Linux system. If you're in Windows, you type something like that, but because we're on Linux, ta-da! And you can do whatever you want. So if we say like C boot slash and then it, you know, goes right in here. Pretty neat, huh? I bet you guys could probably think of a thousand and one uses for this. Anyways, this is Brian. I'm going to keep this one rather short. I have some engagements for the evening. So I hope you found this tutorial educational and entertaining and thank you for watching.