天天看点

Qt数据库判断本地是否已经创建/存在数据库,SQLite

这几天使用Qt 数据库,摸索着怎样判断自己的数据库是否已经存在,和大家分享自己的心得,希望各路大神指点不足或者提供更好的解决方案

bool isTableExist =
    query.exec(QString("select count(*) from sqlite_master where type='table' and name='%1'").arg("CANexcel"));
if(!isTableExist){
    qDebug() << "table does not exist";
} else{
    QMessageBox::critical(new QWidget,QString("创建数据库"),QString("数据库已经存在"));
    qDebug() << "table exists";
    return QSqlError();
           

}

继续阅读