 Hey everybody, this is Brian and welcome to the 60th tutorial in Qt programming with C++. Um, wow, yeah, 60 videos. We've been, uh, we've been really making these things. So today we're going to cover the, what's this? If you don't know what this is, well, we're going to cover it. So let's just make a dialogue and let's just throw a push button out here. Pretty simple little dialogue we've got here. In our dialogue, we'll say UI, push button, set what's this. And if you watch the tooltip tutorial, you know exactly what I'm doing here. Just showing you that the, uh, the rendering is HTML aware. Now compile and build. Now tooltips will show when you mouse over and notice we don't have a tooltip here so nothing happens. This little question mark here is the, what's this? So if you click that and then notice how the icon changes and then you click this button, you get the, what's this help? It helps new users identify what's going on. So let's just say, you know, we've got a highly specialized program here and instead of okay or cancel, this says, uh, you know, release the, release the hounds. Well, what's that mean? What's that do? No idea. So it's just helpful for the user to, you know, be able to select the, what's this and then get a detailed description of what that button is supposed to be. So instead of hello world, we could say, uh, let the dogs out for a walk. Something very simple just to, you know, let the user know what's going on here. Now, excuse me, I don't always do this, but I want to use an example from the cute foundations or I should say foundations of cute development by, uh, Johan felon. I'm sorry if I'm mispronouncing your name. Excellent book. Um, it's one of my favorite books on cute so far. And what he does is actually say, let's put a link in here so the user can click. So we'll just say, well, that didn't work as planned. Let's delete that. And then we'll say, uh, href, single quotes, and we'll just say, and we'll say Google.com, save and run. And when you click this and then you do what's this, you notice there's a hyperlink. Now when you click that hyperlink, unfortunately nothing happens. Well, what this tutorial is going to aim to do is actually make that link work. So when you click it, it does something. So first thing we need to do is create what's called an event filter and we're going to do that. So let's go new class and we'll call this link filter, taking this straight out of the book if you own it. The base class for this is the queue object. Make sure that it has the queue object macro here and make sure that it is the in actual descendant of queue object, which it is. Now what we want to do is add a signal. So we were going to say, void link clicked, help effect it's about clicked, and we want to add protected. And we're going to say, bull event filter. And if you're wondering how I got that to magically appear, you hit control space and it'll give you a list. All right, so there's our header. Not a very complex class, but very, very efficient on the list. So let's actually just make it a little pretty here. Now we go into the implementation file for link filter. And we want to say, bull, filter, and we want the event filter. We need to fill these in here. So we're going to say, object in our event, we'll just call it event. Now what this does is we're going to install this class as an event filter in our form. So whenever an event is fired, it's going to go through this function called event filter, which is going to give us a pointer to an object and a pointer to an event. So we're going to say, very simply, now we need to filter them if event, did I spell event wrong? I did. Sorry about that. I'm still not wearing my glasses. My vision's getting better, but as you can see, I still spell horribly. Why is that not working? Let me pause this for a minute and let me figure this out. Okay, I'm back. I'm sorry about that. I figured out what the problem was. Go back into here and I added a reference to cute core and cute GUI. For whatever reason, it just wasn't picking it up. So let's go back into link filter. Now we can say if event type and we want to know if the type is equal to Q event and we want to know if it's a what's this clicked, meaning that they link inside what's this was clicked. And then we're going to say return true. And if it wasn't, then we're just going to return false. Now as you guessed, we need to perform some type of special voodoo magic in here. So we're going to actually create events. We're going to say Q, what's this clicked event? And we're going to call this WTC event straight out of the book equal and we're going to make a static cast, static cast, not a static case. I want to say Q, what's this event and let's actually go over here because we're not finished yet. I apologize. It's very hard to get the screen real estate and still be able to post these on YouTube because my bandwidth is rather limited at the moment. All right. So let's sign on. It's a big line. So it's Q, what's this clicked event with a pointer called WTC event equals static cast. Q, what's this clicked event pointer? That's actually a type and we're going to use the event. Now what we need to do now that we've created that is actually emit the event. So we're going to say emit and we're going to say, well, I don't know what that was. Link click and we want the WTC event href. So basically what we want to do here is we want to emit link clicked using our Q, what's this clicked event and we want the address or the href reference. And then we're just returning true indicating that something indeed was clicked. Pretty pretty pretty difficult to understand if you're new to this, but really all you need to understand is we're going to be, we haven't done it yet, we're going to be installing an event filter. So every time an event is fired, this class is going to have this function called called event filter. We're going to get a reference to the object or I shouldn't say we're going to get a pointer to the object and a pointer to the event. Then we need to filter and say if the event type is Q, what's this clicked then we're going to get the clicked event out of the event and then we're going to emit the address that was clicked. Let's close that, let's close that. And we are back in dialogue.cpp and as you can see we've just got our what's this. So if you save and run this, nothing's going to happen because we haven't installed the event filter yet. Let's just prove that by running this real quick. So nothing happens but it's good to compile and run just to make sure you didn't have any boo-boos and you're going to want to fix those if you do. Alright, now first thing we need to do is install our event filter. So what we're going to do here is we're going to say, whoops we have to add a reference in here. A little scatter brand today and reference into link filter I should say add and include not a reference and let's just go ahead and include Qt Core while we're at it. Now we can go ahead and we'll say link filter and we'll just create a pointer called filter and we're going to give it this as the parent and we're going to say this install event filter and notice how it takes a Q object. So this is where you're going to hand it off the filter and that effectively installs our filter. Now that the filter is installed we need to set up the signals and slots. So what we're going to do is say connect and the object is filter and the signal we want, we'll say signal, the signal we want for this is the linked clicked event or I should say the linked clicked signal sorry and we want to add a slot here. I don't think we've done that yet have we? No we have not. So let's just say and we want a slot called void show link and we want a const queue string and there's our slot. Flip back in here and where were we oh yes we need to set up our slot here. So we'll say this and we want the slot we just set up. It's not finding it for some reason. What did we do wrong? Oh yes sorry show link not link click silly me it's been a long day show link with our queue string and then we need to implement that and then we can go ahead and just do whatever magic we want to happen when that link is clicked. We'll say queue message box and we'll just do information this and we want a the title to say linked clicked. I apologize for the choppiness of this tutorial I'm kind of following along in the book as I'm doing this because I did not write this tutorial and we want to actually get the link out of here. So what we want to do is just say link whoops and make sure we have our semicolon at the end compile and run and if all goes as planned it's kind of a learning experience for both of us. I read this tutorial and said I really want to do a video on this and I haven't actually done it so this is the first time for me to click what's this there and then when you click your link there is your event filter popping up the message box. Pretty neat just shows you how powerful you can get with Qt. Now notice how if you do this you go here and you don't click the link you just click somewhere else it just disappears that's how you know that filter is really really working. So this is Brian this was our 60th tutorial. I thank you for watching I hope you found this video educational and entertaining and remember this tutorial came out of the Foundations of Qt Development from Johan Felin I'm sorry if I'm mispronouncing your name. Excellent book I have learned a lot from this book I recommend you run to the store not walk run as fast as you can as fast as your little feet will carry you and buy this book it was well worth the cost.