工作代码片段-qsqlite
打开数据库:
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
database.setDatabaseName(mDataName);
if(!database.open()) {
p; return false;
}
QSqlQuery *queryer = new QSqlQuery();
查询数据库:www.zzzyk.com
QString selectStr = "";
for(<pre name="code" class="cpp">QList<QString>::iterator iterator = args.begin();iterator < args.end();iterator++)
{
selectStr += *iterator + ",";
}
selectStr.remove(selectStr.size() - 1, 1);
QString queryStr = QObject::tr("select %1 from %2").arg(selectStr,table);
bool flag = queryer->exec(queryStr);
if(!flag) {
std::cout << "数据库查询失败" << std::endl;
return;
}
if(!queryer->first())
{
std::cout << "没有数据" << std::endl;
return;
}
do{
proxy->execut(queryer);
}while(queryer->next());
关闭数据库:
if(queryer != NULL)
{
delete queryer;
}
database.close();
添加数据库插件搜索路经:
QApplication::addLibraryPath(QObject::tr("./plugins"));
添加编译选项:
QT += core gui sql network
摘自 缘起
补充:软件开发 , C++ ,