 Hey everybody it's Brian and welcome to the 56th Qt tutorial with C++ and GUI programming. Today we're going to be covering the Qsql table model and I've already got some code written because I didn't want to waste your valuable time. In our project we just have a reference to SQL and in our main window .h we are using a main window instead of a dialogue. We have some includes. We've got Qt debug, Qt GUI, Qt core and Qt SQL. In our private section we've got Qsql database named it DB and Qsql table model and it's just a pointer to model and in our implementation very simply we're just setting the central widget to the table and opening the database connection here. Haven't done any real error handling just for the sake of simplicity. Let's just save and run, build this thing, make sure there's no major problems going on here. If you've been following along with these tutorials you already have a DSN set up called MyDSN32. Just going to show you the structure of my database real quick. We have one table called test, I'm sorry one database called test with a table called people with three columns ID first name last name and we have Bob Hope, Will Smith and my daughter Heather Cairns in there. Alright now let's get to the heart of this tutorial real quick here. What we want to do is we want to populate our model and then display it. So we need to say model equal new Qsql table model and now we want to say model dot set table and we want to give it our table name and then we want to say model select and that selects the data and puts it into the model and now we want to display the model so we'll say UI, table view, set model, alright save and run. Now if you build this and everything goes as planned you'll have data but if you've been following along religiously with my tutorials you probably came up with something that had no data in it. Let me demonstrate that. Here's our DSN, configure, next, next, notice how I have this change default database too and I have the actual database name selected. If you didn't do that because I haven't told you to do that then you end up with just a blank window like this with no data in it. So if you get that and you're struggling and trying to figure out what in the world is going on here, there's a little trick I'm going to show you here. You can say queue debug, model, last error, text and when you save and run this it says unable to find table people right down here. The reason why I can't find the table is you haven't told it where it is so you go back into your DSN, just go configure, next, next, change the database to and then give it the database you want to work with. Very simple. That's how you solve that problem and voila, there's our data again. Now one thing you should note is that this is editable. You can go in here and say willsmith, baby, hit enter and when you go into the underlying database you see there's willsmith and we'll just refresh that and it's changed. Now willsmith in my personal humble opinion gets a little annoying after a few movies so we're just going to change it back to willsmith. You can see the data change back. Very simple, very powerful control, lets you very easily allow the user to modify information. This is Brian. Thank you for watching. I hope you found this video educational and entertaining.