m_dbTest = QsqlDatabase::addDatabase("QsqlITE"); m_dbTest.setDatabaseName("sqlite.db"); if(m_dbTest.open()) { qDebug() << "database succeeded to open"; } else { qDebug() << "database Failed to open"; } QsqlQuery query(m_dbTest); bool isTableExist = \ query.exec(QString("select count(*) from sqlite_master where type='table' and name='%1'").arg(strTableName))); //关键的判断 if(!isTableExist) { qDebug() << "table does not exist"; } else { qDebug() << "table exists"; }
FROM: http://blog.chinaunix.net/xmlrpc.PHP?r=blog/article&uid=29650836&id=4457672