Void mainwindow: conect () {/* QT demos or exmples provides usage of SQLite databases. */Qsqldatabase DB = qsqldatabase: adddatabase ("qmysql"); // use MySQL to load the MySQL driver dB. sethostname ("localhost"); // set the host name. You must set the host name dB before connecting to the database. setdatabasename ("test"); // you can specify the database name dB. setusername ("root"); // username dB when logging on to MySQL. setpassword ("123"); // The bool OK password when logging on to MySQL = dB. open (); // open the database if (OK) {qdebug () <"Open Database! "<Endl;} else {qmessagebox: Critical (0, qobject: TR (" database error "), DB. lasterror (). text () ;}} void mainwindow: Execute () {qsqlquery query; // execute the SQL statement query.exe C ("CREATE TABLE employee (ID int (11) primary key, name varchar (50), description varchar (255) "); // create the query.exe C (" insert into employee values (1, 'anpan', 'student ') "); // insert data query.exe C (" insert into employee values (2, 'caoling', 'student ') "); query. Exec ("insert into employee values (3, 'lvsumei ', 'student')"); query.exe C ("insert into employee values (4, 'panjiaoli', 'student ') ");} void mainwindow: Display () {qsqltablemodel * model = new qsqltablemodel; // data model-> settable (" employee "); // set the table 'employee model-> seteditstrategy (qsqltablemodel: onmanualsubmit); // All changes will be cached in the model until submitall () or revertall () the model-> select (); // select () function is called to check the status of one or more interfaces. For each set of interfaces, the caller can query its readability, writability, and error status information model-> setheaderdata (0, QT: horizontal, qobject :: TR ("ID"); // set the header model-> setheaderdata (1, QT: horizontal, qobject: TR ("name ")); model-> setheaderdata (2, QT: horizontal, qobject: TR ("Description"); this-> UI-> tableview-> setmodel (model );}