[cpp] view plaincopyprint?
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("support");
if(!db.open())
{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
QSqlQuery q;
q.exec("create table student(id integer primary key,name varchar,age integer)");
q.exec("insert into student(id,name,age) values(1001,'AnPan',21)");
q.exec("insert into student(id,name,age) values(1002,'CaoLL',22)");
return true;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("support");
if(!db.open())
{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
QSqlQuery q;
q.exec("create table student(id integer primary key,name varchar,age integer)");
q.exec("insert into student(id,name,age) values(1001,'AnPan',21)");
q.exec("insert into student(id,name,age) values(1002,'CaoLL',22)");
return true;