 If you've watched any of my video series before, you know that I don't like to stick around and begin or land very long. I like to dive headfirst into the complex stuff because, well, I generally think that people that watch these videos are usually pretty smart to begin with. This series is going to be no different. We're going to dive headfirst into what's called model view programming or specifically the model view controller design pattern. MVC is very complex and I am not even going to joke with you. This is something that experts have a hard time wrapping their head around. We're going to introduce this in the beginner series and we're going to continue this on in the intermediate and advanced series as well. So first off, what is an MVC design pattern and why do you need it? Well, it's a model view controller and it's deceptively simple. You have a model which represents the data but isn't actually the data. You have a view which is what's displayed to the end user and a controller which controls the interaction between the two. Sounds simple and introduce this graphic. Now suddenly we're confused. So you have a model which represents the data but is not the data. You have a view and wait, there's no controller. Isn't this MVC? Well, there's a delegate. So cute way of doing this is they call it a delegate which acts as a controller. So you have the model chit-chats with the back-end data that coordinates with this delegate or this controller who also coordinates with the view. But the view can also pull straight from the model. Sounds confusing, doesn't it? Well, it's because it is. This is a very complex topic. Think of it this way. If you just want to view raw data, you can just pull straight out of the model. If you want to do some sort of custom rendering or editing, you've got to go through the delegate or the controller. I don't really like this graphic because it's hard to understand. So we're going to flip over to Google and you can see here's that same graphic. But here's what I would consider almost a better way of understanding. So we have the model, the view, and then this controller which kind of connects or acts as a bridge between the two. You can see how we've got updates and things like that. So it actually starts over here. I almost wish it was flipped where there's a user action. It goes to the controller. The controller says, do something. Model notifies the controller. The controller comes back and says, update the view. Here's an even better graphic. User says, hey, controller, I'm making a request. Give me all your cats. Controller says, well, I don't actually have the data that's in the model. So model, give me all cats. Model will return some sort of representation. The controller says, well, it's not my job to show you. That's actually the view. The view says, oh, I know how to show this and sends the response back. Actually, this web page that we're looking at here is a perfect example of this pattern. You're looking at the view, this guy right here. The controller is probably some source code on a server somewhere and the model is probably a giant database. There are vastly more complex ways of looking at this. And depending on what graphic you want to look at, everybody's kind of got their own way of really talking about this. And it gets really, really complex. Stack Overflow has a really good conversation called, what is the difference between an MVP and an MVC? This is another thing that people get drastically confused. So we're talking about an MVC, but there's also concept of an MVP. And no, I'm not talking about most valued player. So MVP is a model view presenter. In an MVP, the presenter contains the user interface business logic of the view. What? That makes very little sense because we're supposed to separate the business logic and the view. But that type of model actually exists and a lot of people use it and don't even understand what it is. Where an MVC, well, the controller is responsible for determining the view, not the user interface. So scroll down and this graphic is just beautiful because it shows you that you can have multiple views, multiple models, a single controller or multiple controllers, and MVP is very different. You have views, views go to the view interface, which go to the presenter, which go to the model. So kind of think of this layer right here as the controller and MVP. Just understand that there's two different models and they can get very, very complex. Back to Qtland. Qt comes baked in with some already existing models. For example, a string list model. Remember the model is not the data. String list model so you can actually present strings. Standard item, which basically you can do complex structures and you can do just about anything with this. Q file system, which takes that standard item model and basically makes a model around your file system. And then the Q SQL query, SQL table and SQL relational table. These are all highly complex things, but basically that talks to it back in database. We will not be covering that in this series because it's so complex. Now there's also an abstract table model and item model and list model. So if these don't suit your needs, you can actually build your own right from scratch. You have views, delegates, sorting, convenience classes and so on and it gets really, really complex. I know I keep saying that, but don't underestimate how powerful and yet complex this really is. For example, here's the same data represented in two different views. You have your file system, you have like a details view and then just a simple view. Same data, different views. Qt handles all that under the hood. Now the basic concepts here is you'll have different types of models. You'll have a list model, a table model and a tree model. The list will just have a root with children. Table will have a root with rows and columns. And the tree will have a root with children who can have children who can have children. And you can actually kind of to some degree mix and match these. It gets kind of nuts. Qt, their official documentation does probably the best job of anybody I've ever seen that really tries to explain this. But honestly, you're not going to get it to start working with it. And to make things even more complex, the view itself has sub items. You've got to really understand, for example, roles like a display role, a decoration role, a tool tip role. It just gets insane. So take some time, dive into the documentation and just kind of see how they do things and how things in the Qt world are set up and just how complex things can become. But we are going to have some very realistic examples here. I want you to be intimately familiar that a couple of the core concepts right off the bat and I'm just kind of scrolling through to show you just how long and I'm going to speed up. That's a humongous amount of information to go through. But we're going to cover a lot of the core concepts here. They do have some really good examples. Unfortunately, they come with very limited documentation. And it's kind of up to you to read and digest everything that I just scrolled through. And if you don't really understand that, you're left scratching your head. So we're going to break this down into simple understandable chunks. And we're going to really explain how the model is not the data. The view displays the view to the end user. And the controller is this in the Qt world, almost this magical thing that you just interact with and it generates the information for you. I hope you enjoyed this video. It's part of a larger project out of you to me called Qt 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 Qt Widgets. I will make a QML course later on, but this just focus on widgets from a beginner's perspective. Even though this is a beginner's course, you do need to have some fundamental information available. You need to know C++ and the Qt Core Libs. I do have some courses available out on Udemy, Qt 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.