 All right, so what we've already described is that pretty much everything's driven by this infamous Q-Widget and Everything is driven by signals and slots So let's really look at what's the best way to use a signal and slot and why would you do it a specific way? Like I said earlier, there's multiple ways of doing this. So we're just going to make a Q dialog app next next finish to crack open our dialogue here and And Let's go ahead and add a few things. We're going to say include Q debug Yeah, let's go ahead and include Q date time We've covered these pretty in-depth in our Qt core series But in case you don't know what they are you can always look them up in the official documentation You can also select something and press F1 and it'll bring up the documentation for you Just in case you're ever confused Now buyer beware the documentation is world-class, but it's usually not the complete story So when in doubt always refer to Google or tutorials So we've got Qt debug Qt date time Debugs going to allow us to put debug messages out onto the console and Date time is going to allow us to work with while you guessed it dates and times We're going to make three distinct buttons here. Let's actually go out to our UI And let's resize our dialogue a little bit and we're going to make three buttons Just gonna wherever I feel like on the form here And we're going to say internal Let's call this button internal Let's call this editor and you may have guessed what we're going to be doing here We're going to connect signals and slots up in different manners and see which one's the appropriate way for different situations here And this one's going to be called connect Now in case you're wondering why I'm typing on the button correctly instead of using This little object inspector here. It really doesn't matter which way you do it Both of them are going to give you the same results. So I could have very easily just said text and then Connect and then you notice how it keeps the filter as I select objects There we go. I'm going to you guessed it set a vertical layout here that way. It just looks nice and pretty So we have three buttons Save and run just to make sure we get a good build and our beautiful application does absolutely nothing Let's go ahead and fix that problem So let's flip back to our dialogue real quick and what we're going to do here is we're going to add a private slot I'm gonna say private slots and let's just say avoid Do stuff the ever descriptive do stuff Right-click Refractor and then we're going to add the definition inside of representation notice how you have different options I almost always do it inside of the implementation file that way. It's nice neat easy to follow All right now in our implementation file what we want to do is actually be able to see what's going on So we're gonna say Q info this comes from our Q to bug import and we want to say hey it was clicked Then we get the Q date time Get the current date and time and we want to just do a simple two string Make life super easy on us and then we're just going to accept this out Now notice how except is being called and this will close the form So if you want to comment that out for testing you can and we may actually just do that just so we can See it in action here. Now, let's jump back here. We've got our three buttons. We've got an internal We've got the editor and connects. So let's look at internal Internal is just you know, if you're kind of in a hurry and you just want to go bang bang You're just gonna click drag and then we're gonna say clicked and then we want to just accept it and that works great in a pinch We can save and run this and It's gonna work as expected. No questions asked, but It didn't put any output. We didn't see that little debug message That's one of the gotchas of it is it's really not super helpful unless you just want to call a Slot right away and you don't really care about what's gonna happen The other way is using the editor where you actually right-click go to slot And you can see how well we have clicked In the Q abstract button we have Q widget with Q object But we don't have direct access into this dialogs slots like if we go back in here real quick Remember we made this slot, but we don't have access to it so This is kind of just hey if you want to build a special function for it without having to go through the hassle hassle of building your own slot Then we'll just go in here, and then we could just call this directly. So now we can save and run You know how now we have our Debug info Where if we click this because it's just that internal it's not gonna do it Let's go ahead and clear all that out Now let's look at the last way of doing things and this is actually Some people call it the preferred mains, but it really doesn't matter. It just depends on how you want to do it So we're going to connect this up And we're going to connect the UI notice how when we do Dot we now see our controls here. So we're gonna do the button connect and I'm gonna say you push button and we want the clicked Signal do the signal not the slot. So I say clicked and then we're gonna connect this to our dialogue Now we can call our slot directly Now if this is really confusing and you've never done this before I would highly recommend you read up on Q object bit of shameless advertising take my Cute core for beginners intermediate advance on you to me Or just run some tests yourself and there's a lot of documentation how to connect signals and slots But the basic structure is you're calling connects and you're saying this object This signal is gonna connect to this objects slot So when this happens run this that's really what you got to focus on when this happens run this and honestly Your UI designers doing pretty much the same thing you see right here slot except So signal So you got the sender is the button the signals clicked the receivers the dialogue the slot is accept So it's doing all this for you in the background Now what is the preferred method? What really depends on what you're trying to get done here? So Save and run if you just want to call it and you don't care and it's kind of a built-in thing Yes doing the internals perfectly fine if you want to make your own little function here and do some extra stuff here Like well, then you would do the editor method, which is where you right-click the button and go to slot Otherwise usually the best method is you actually create your own connection. That way you could fully manage what's going on So let's do that and let's finish this app up and really demonstrate here. So Let's call this cute critical Actually, let's do Q debug instead Do I have an extra Q in there? I do how embarrassing. All right We're just going to debug some stuff out and say extra stuff and let's save this And let's run so we can connect signals and slots automatically by the internal and nothing happens Run that again. We've done it through the editor We're calling the special function that it created for us and we can add some extra stuff and call other functions You see extra stuff clicked and then the actual connect code that we did our self This is like the highest degree of control right here. So that really demonstrates the three different methods I hope you enjoyed this video. It's part of a larger project out of you to me called cute widgets for beginners with C++ 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 cute 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++ and the cute core lives I do have some courses available out on you to me cute core beginners in a mean advance It's not necessary you take these courses, but it is highly recommended And as always I'm available out on the void realms Facebook group along with 3,000 other programmers. See you there