cpp]
view plain
copy
print
?
![在CODE上查看代码片](https://code.csdn.net/assets/CODE_ico.png)
- 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";
- }