测试:
这里有一个sqlite数据库

存储了10万多条数据,col1是1,col2是2.

使用QSqlQueryModel和QTableView来显示这些数据,也非常非常流畅。
cpp
QString aFile = QString::fromLocal8Bit("E:/桌面/3.db");
if (aFile.isEmpty())
return;
//打开数据库
DB = QSqlDatabase::addDatabase("QSQLITE");
DB.setDatabaseName(aFile); //设置数据库名称
if (!DB.open()) //打开数据库
{
QMessageBox::warning(this, "错误", "打开数据库失败",
QMessageBox::Ok, QMessageBox::NoButton);
return;
}
qryModel = new QSqlQueryModel(this);
qryModel->setQuery("select rowid,col1,col2 from test;");
if (qryModel->lastError().isValid())
{
QMessageBox::critical(this, "错误", "数据表查询错误,错误信息\n" + qryModel->lastError().text(),
QMessageBox::Ok, QMessageBox::NoButton);
return;
}
tableView = new QTableView;
tableView->setModel(qryModel);
this->setCentralWidget(tableView);

可以看到数据是动态加载的。