【1】创建带名称的数据库
cpp
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlRecord>
QString path = QDir::currentPath();
QApplication::addLibraryPath(path+QString("/release/plugins"));
QPluginLoader loader(path+QString("/release/plugins/sqldrivers/qsqlite.dll"));
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "myDataBase");
db.setDatabaseName("c:\\myDataBaseName.db");
【2】代码中的"myDataBase"是一个sqlite的连接对象名称,对于同一个数据库文件,通过修改连接名称,就可以实现多个连接。否则就会踢掉上一个连接
【3】"c:\\myDataBaseName.db"是数据库文件的绝对路径,通过设置名称,就可以访问不同的数据库