sqlitedemo.pro
#include #include #include #include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db; QDir dir(QDir::currentPath()+"/temp"); if(!dir.exists()){ dir.mkdir(QDir::currentPath()+"/temp"); } bool isExist = QFile::exists(QDir::currentPath()+"/temp/my.db"); if(!isExist){ db = QSqlDatabase::addDatabase("QSQLITE","my"); }else{ db = QSqlDatabase::addDatabase("QSQLITE"); } db.setDatabaseName(QDir::currentPath()+"/temp/my.db"); if (!db.open()) { qDebug()<<"open database failed ---"<