 Hey everybody, this is Brian and welcome to the 26 Qt tutorial with C++ and GUI programming. Today we're going to cover the Q message box, so let's just go file new, new Qt GUI application and it's pretty much the same thing we've been doing. Put it in the usual location and we're going to give it a Q dialog. Just hit OK and finish and once we get our window here, let's just resize this a bit. I'm going to throw a few buttons on here and we're going to say information, question, let's probably make that a capital and let's line that up here, warning and let's just say custom. All right, let's set our layout and resize as needed. So we've got four buttons here, information, question, warning and custom and we're going to show a Q message box and we're going to make it different each time. So let's select information, go to slot, clicked and then there's our and let's just type info so we know which one this is and we need to add our includes before we do anything else. We're going to get some weird error messages here. So let's go include, QCore and include QCui. All right, save our work. Now the Q message box, you've seen this many, many, many times so far, so this is going to be relatively review for you, but we're going to show you a few new tricks so pay attention. All right, so Q message box information and the parent will be this and the string or the title. We'll just say title here and let's actually drop down the line and then we need the text and then you can actually keep adding things. For example, you can add buttons. We're not going to do that for the information. We just want a standard information and let's go back to our form but first we're going to copy this then we're going to do question. So just go to slot, clicked and it's pretty much the same thing. The only difference is you have to add buttons to the question because you're asking a question. So what sort of buttons do you want to add? Well the type of buttons depend on the question you're asking. So let's just say do you like cats and let's go down here and go Q, oops, something else popped up and stole my mouse, sorry about that. Q message box, yes and we want to do an or so Q message box, no. We just want to give them a simple yes or no and there are other options you can explore but for the Q question or I'm sorry the Q message box with the static question we're just going to do yes or no. All right, let's save and run this. Just make sure it works so far and click information and there's title here, text here, you see it's got the information icon and question do you like cats, yes or no. So one thing you might be asking is well how do you get the response back from the user? I mean how do you know which button they clicked? Well that's a good question. So let's say Q message box, standard button and we'll call this reply and then we're just going to simply say reply equals. So once you've said reply equals and then you can just grab the reply and let's just say if reply equal and we'll say Q message box, yes, then do some things. So in this case we're just going to say, actually I'll just copy this for the sake of argument we're going to just display an information box here saying you like cats. Actually we'll say you love cats. There we go. Let's get rid of that text. So just kind of over-inundating the user with message boxes here. So let's compile and run this. Uh-oh we have a bobo, invalid use of non-static message, expected before reply. What did we do wrong here? I think we have the wrong type, standard button, there we go, yes we did have the wrong type, we had the lowercase version, we want the uppercase version. The difference between those two is the standard button lowercase is an object, the standard button uppercase is an actual enumeration. So let's compile and run this. Do you like cats? If we say no, nothing happens. If we say yes, you love cats. So let's say you get the response back from the Q message boxes, you just do a Q message box standard button. Or the capital, and give it a variable name and then say variable equals, that's how you do that. Alright, now what about our others, the warning and the custom? Let's go to slot, clicked, and you guessed it, just warning. And it's got the same argument list so we really don't have to do a whole lot there. And then custom, and let's go to slot, clicked. And this way we're going to have a little bit of fun with here. So let's actually get rid of that. Let's say Q message box, question, this, this, and we want to do the title. So we'll say my title and then the text and we'll say my, whoops, having keyboard difficulties here today. My text here and then we have buttons. This is where the real power of a message box comes in. You can add all sorts of buttons. So we'll say Q message box and we'll say yes to all or Q message box yes or Q message box. No, I'm sure you've seen a dialogue similar to this at one point. You can kind of guess what I'm building here and we'll say Q message box and no to all. And add our semicolon here. So save and run this. Alright, now warning, warning has the typical warning icon. You've noticed that these dialogue boxes are all very similar code-wise but they look very different. It's all about relaying information back to the end-user and we click custom. My text here, yes, yes to all, no, no to all. So you could say something like are you sure you want to overwrite this file? Yes, yes to all, no, no to all. And then you can just simply grab the response back using this technique I showed you here. We'll just copy this and paste it. Whoops, silly me, I put it in the wrong one. Go down to our custom here. It's that simple. Working with message boxes is relatively easy in just about every language and Qt gives you an extensive amount of options with the message box. You can do literally just about anything you can think of with a message box. So by all means use them. Your users will love you. Don't pop one up on the screen every five seconds and well, you know how the users will act with that. This is Brian. I hope you found this video educational and entertaining and thank you for watching.