Finally in Qt the operation of SQLite successfully, write a summary of it. In fact, the right time, but to view the database is not desired results. The final discovery of the generated execution file in the Dbug directory, unlike the previously set path, dawned.
First, to use the database module, you need to include in the Pro file:
QT + = SQL
Second, the required database operations related header files:
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField>
third, connect SQLite
1 voidDbcon ()2 {3 Qsqldatabase db;4db = Qsqldatabase::adddatabase ("Qsqlite");//indicates that the database type is SQLite5Db.setdatabasename ("test.db");//test.db database file opened or created in the directory where the program is located6 if(Db.open ()) {//Open database, loan processing7Qmessagebox::information ( This, TR ("Connect ..."), TR ("database connection Failed!"));8 return;9 }Ten}
Four, the operation of SQLite a case
1 voidInsertData ()2 { 3 //Once the database is open, try to get to the Operation4 qsqlquery query;5 //query.exec ("CREATE table User (name,information);");//If there are no tables in the database, then create one.6Query.exec ("INSERT INTO admin values ('%1 ', '%2 ');"). Arg (name). Arg (pass));7Db.close ();//Close the database8}