http://www.cnblogs.com/lgh1992314/p/3488342.html
建库
在VS下新建qt console appication
代码:
#include <iostream> #include <Qtsql/QsqlDatabase> #include <Qtsql/QsqlQuery> #include <QtCore/QCoreApplication> #include <QDebug> #pragma comment(lib,"Qt5sql.lib") int main(int argc,char *argv[]) { QCoreApplication a(argc,argv); QsqlDatabase db = QsqlDatabase::addDatabase("QsqlITE"); db.setDatabaseName("user.db"); db.open(); QsqlQuery query; query.exec("select * from student"); while(query.next()) { int id = query.value(0).toInt(); QString str = query.value(1).toString(); qDebug() << id << "|" << str; } db.close(); return a.exec(); }