当前位置:数据库 > SQLite >>

工作代码片段-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++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,