first, it refers to a conventional Code on the network, but many problems are encountered in actual use, paste the Regular usage as follows:
# Include <qtcore/qcoreapplication> # include <qtsql> # include <qtextcodec> int main (INT argc, char * argv []) {qcoreapplication A (argc, argv); qtextcodec:: setcodecfortr (qtextcodec: codecforlocale (); qsqldatabase dbconn = qsqldatabase: adddatabase ("qsqlite"); // Add the database driver dbconn. setdatabasename ("mytest. DB "); // create a new mytest in the project directory. if (! Dbconn. open () {qdebug () <"fdsfds" ;}qsqlquery query; // run the following QSL statement query.exe C ("create table student (ID varchar, name varchar) "); // create a student table with the ID set as the primary key. There is also a name item query.exe C (qobject: TR (" insert into student values (1, 'aaa ') "); query.exe C (qobject: TR (" insert into student values (2, 'bbb ') "); query.exe C (qobject :: TR ("insert into student values (3, 'ccc ')"); query.exe C (qobject: TR ("insert into student values (3, 'ddd ') "); query.exe C (qobject: TR (" insert into student values (4, 'Eee ') "); query.exe C (qobject :: TR ("insert into student values (5, 'fff')"); query.exe C (qobject: TR ("insert into student values (6, 'ggg ') "); query.exe C (qobject: TR (" select ID, name from student where ID> = 1 "); query.exe C (" select ID, name from student where ID> = 1 "); While (query. next () // query. next () points to the first record found, and moves one record after each time {int ele0 = query. value (0 ). toint (); // query. value (0) is the ID value and converts it to int-type qstring ele1 = query. value (1 ). tostring (); qdebug () <ele0 <ele1; // two output values} query.exe C (qobject: TR ("Drop student ")); return a.exe C ();}
the above method is not good, but there are a lot of inconveniences during use and many problems will occur. I will modify this idea in the following section, and then implement it again in general software development mode.