 All right, let's take a look at the combo box. It's down down down here in input widgets You don't see it right away. You got to just scroll down or you can just search in the filter Gonna drag and drop it here The combo boxes well kind of like me without coffee in the morning It doesn't do a whole lot without some real encouragement So we're gonna show you how to work with this thing drag some other controls on and let's go get the label and Let's put these in some layouts here Doing things slightly different just to show you how you can do it in multiple ways All right, let's save and run and like I said it does very little actually nothing without some encouragement so Really what the combo box does is when you click it it'll drop down a list of options the user can choose from I know you've probably seen this all over the place by now, but we're gonna show you How did I actually work with it? Let's say select an item this is where we're gonna have the selected item and Let's actually you can either right-click and edit items or you just simply double-click it brings up the combo box editor And we're gonna manually add some items Dogue try dog cat bird and Lizard All right, so let's say you put something in here. You don't want you can just simply Remove it and you can also change the ordering on these things Each item has properties so you can just select something go to properties and you can see the text and all the other properties Some of these get a little advanced. We're not gonna really cover them because we're still in the beginner phase Hit okay, and you can see it's now populated save and run This is the expected behavior of the combo box you click it opens up the list of items You can choose an item. This is a zero based index. So zero one two What we're gonna do is allow the user to select an item show them the item they selected if they click save We're gonna save it to disk and then when they reopen the application We're gonna load it right back to the item they selected. Let's go over to our dialogue here We're gonna say Q settings Q settings allows us to save and load settings off to the disk very easily Q variant Q variant allows us to Put different variable types into a variable So you could put like a string or bowling or integer and then easily get those back We covered both Q variant and Q settings in the Q core series out on you to me and Q message box Along with this we're gonna have some other functions as well I'm gonna say void in it Void load Let's jump into our interface here Right-click this go to slot And you see there's different signals that are emitted from the combo box We're gonna want current index change doesn't really matter which one of these you do but I'm just gonna do the current index changed int and We are going to go to slot for the button clicked implement these functions Now the thing all about programming is there's multiple ways to solve the same problem what a lot of programmers like to do is Put all of their initialization and everything right in the constructor and it becomes kind of a mess to really figure out What's going on when something doesn't work the way you want it to I? Tend to separate the logic out that way. It's very easy to follow very easy to understand what's going on so Dialogue's gonna load it's gonna set up our user interface then we're gonna initialize some data Then we're gonna load the user save data So let's jump down to initialize We're gonna clear out any old data that we've already got in there We're gonna say for let's just do a for loop here increment that I And you notice there's add item and add items add items plural Lows you to take an already filled out list and just shove it in one line of code easy and done We don't have that list so we're gonna add them in one at a time And we're just simply gonna say Going to take that index and just turn it into a queue string and put it right out there Once we're at that point. Let's go ahead and test this out see what it looks like and Sure enough. There's our zero based list and The user can select and choose items from that list Now we're gonna work with the combo box current index change So when the user selects something we want to actually do something with that information. So we're gonna say UI combo box Actually, we're gonna say UI LBL selected set text UI combo box and we want to get the Current and you can see there's current data current text and current index well Current text is the same thing as if you were to do the current index change with the queue string Current index is the same thing as literally this right here. Ta-da. So we're gonna go with current text Now just to show that we can grab both of those Now when the user selects something we're gonna show not just the index, but also the text Very quickly very easily say hey for item number four And we could clean this up a little bit Just by simply putting an equal sign in there. So it's a little more representative of what's going on zero is item number zero Four is item number four Let's go ahead and write the code that's gonna save this stuff So when the user clicks that save button or say queue settings Again, we've covered queue settings and queue variant in the queue core Tutorials out on you to me strongly strongly strongly advise you go watch those if you don't if you haven't if you have no interest in it You can just simply select queue settings hit F1 and it takes you right to the help file So settings we are going to set value We need to give it a queue string key And now let's give it a value the value. We're gonna give it is the UI combo box Current index so we want to get the index of the currently selected item If there is an item in the combo box in that list at all, even if you just have one item There will always be a current index Now let's say queue message box Information we just want to give the user some guidance here We're gonna say select to say please close and reopen the application that way the user knows hey something happened We need to do something else. Otherwise, I'll just click that button over and over again and go nothing's happening All right, so now we have our load Function here. This one's a little bit tricky and I'm gonna explain why I'm gonna say queue settings settings and Let's say value and notice how we've got that key, but then we can get a default value so Want to make sure that key lines up And want to make sure we have a default value and this is what I want to really go into This is a key value pair and if the keys off so if we have set or setting It's two different things. You want to make sure that this really lines up with us What we're gonna do is grab this guy Q variant value and we're gonna get that value Notice how we have a default default zero because this is a zero based list inside the combo box That means the default is going to be the first item in the list This is another little gotcha here If we say something like value Lesson UI combo box Count Well, what are we doing here? Let me get some screen real estate for us What are we really doing here? We're saying if the value is less than the count So we're trusting that this value is automatically an integer This will actually work on some operating systems and not work on others This ran flawlessly on my Mac did not work on my Linux box So you would have to say To int but notice how there's this bull no pointer So what we really should do before we even attempt something like that Is convert that variant into the value type that we want? Let's say it Index equal value dot To int We're gonna use a boolean. We're gonna pass that over and then we're gonna say if Not okay, meaning something bad happened We want to let the user know and then we want to get out of here If you see something like this where you're trying to load that in and it's just not working Chances are the user's been playing with it And what do I mean by playing with it when you use q settings this guy? It's going to save it out either into the registry on windows or into an i and i file on any other operating system And it's a plain text file the user can easily crack open and start modifying um Not really Wanted in some applications, but by default. That's just the de facto way that things are done So we're just going to say hey if we could not convert this Then let the user know something bad happened And then return out Now we have another case here where the user could have gone in there and put in some abstract number like that Or even 81 We've only got 10 items in that list. So this would actually fire off. So we want to make sure that hey um We want this to be less than the count. We want to make sure this works and if not then yeah We want to do something about that. We're gonna set Current index to zero by default just in case something Goes awry Otherwise A little bit of sanity checking this is probably vast overkill 90 percent of the time But I just want it in there just in case Last rudimentary check of our code. We're going to start we're going to set up our UI. We're going to initialize. We're going to load When we go into load If there's been nothing saved, we're going to default to zero Sure enough loaded Let's select like item four click save Selection save please close and reopen the application Go ahead and close that Now when we rerun this It's going to load but it's going to have a four in here And then it'll do all this code save and run Item four, so let's select a different number here. Let's say two rerun it. There we go Simple to use easy to understand once you wrap your head around the basic fundamentals of the combo box I hope you enjoyed this video. It's part of a larger project out of you to me called acute widgets for beginners with C plus plus This is a large course with 73 lectures and 17 hours of video footage This course covers everything from what is a widget all the way down to complete example applications Using the skills you've learned in this course Sorry, there's no qml in this course. This is strictly acute widgets I will make a qml course later on but this just focus on widgets from a beginner's perspective Even those as a beginner's course you do need to have some fundamental information available You need to know c plus plus and the cute core libs I do have some courses available out on you to me cute core beginners intermediate advance It's not necessary. You take these courses, but it is highly recommended And as always i'm available out on the voidrom's facebook group along with 3 000 other programmers. See you there