 Hey, everybody, it's Brian and welcome to the 55th Qt tutorial with C++ and GUI programming today We're going to be covering the Q SQL query model and we're just going to make a GUI application And call it my Q SQL query mod Pretty horrendous application name. I know starting to run out of ideas if you have any ideas for application names Just let me know maybe I'll start naming everything bacon or something And then we'll say a Q dialog Next next finish finish and we're going to have a very basic Layout here because I'm pressed for time. We're going to throw a tape of you out there And first thing we need to do is update our project file give it a reference to SQL And notice how it'll re-scan your project over here once you do that All right now we have to add in our includes we'll say include And I've gotten quite a bit of flak for doing this and I apologize. It's just much faster We'll say Q SQL Forget the T in there. That's why it's not coming up. Hmm, of course as soon as I say it's faster. It's not faster That's just how life works there we go And include all right got our includes in there now what we need to do is we need to set up our models So say Q SQL query Model right there, and we're just going to call it model And if you've been following along in my other tutorials with the model view architecture This is nothing new. The only thing you're doing is you're creating a Q SQL query model So the underlying data source instead of our file system or custom data is going to be the SQL database So let's just jump right into dialogue CPP here and we're going to set up our database connection and we'll say Actually, we should back up here and actually throw it over here in our header We'll say Q SQL database. Whoops, and we'll just say whoops DB Equals sorry Q SQL database and remember we want to set up our driver. So we're going to just add the Q OD BC and Then we want to set the host name Very important to do the double slashes. Otherwise, it'll see as an escape character And I'm using SQL express but you can use whatever database system you want We're going to set the database name and in previous tutorials I created a DSN and Let me show you that DSN super quickly here because we're pressed for time in some of these videos There's my DSN 32 if you have no idea what a DSN is or what I just showed you Please go back and watch my other tutorials. I cover that pretty in-depth. All right Now What we need to do is set the query, but first thing we got to do is open the actual database We're gonna say DB dot open. We'll close our connection here. We'll say give me that close Somebody's probably gonna mail me and yell at me and say you can't close that during the deconstructor But you know what? Let's just try it. So let's compile and run And let's just make sure there aren't any horrendous bugs in our application here. All right So our application starts. There's no major meltdowns going on Let's continue So first thing we need to do is set our model so we'll say and we're going to say new cue SQL query model and Then we want to set the query. So we'll say model and we're just going to flip over to our SQL express management studio and I've got a here's my SQL server I have a test database and I have a table called people and in there I just have some columns ID first name last name And we'll just go script table and select new query window And you can execute that and you can see this is the result it returns I have Bob Hope will Smith and my daughter Heather Karen's who is now famous forever ever more and we'll just Format the string and select this and That is our query string and that is how it populates the data the data will not be in there until you do a set query So then we'll say UI table view And we'll say set model and we're going to give it the model Save and run and with any luck this will build correctly and there's our data that is how you do a Q SQL database in a model view architecture Using the Q SQL query model now. You should note that this is not editable. You cannot edit this at all What we will be covering in the next few ones are how to edit this data and it will automatically persist it back into the database for you So this is bright. Thank you for watching. I hope you found this video educational and entertaining