PDA

View Full Version : Missing rows in QSqlTableModel



bull3t
24th March 2020, 10:19
Hi,
i'm loading a table in a sqlite db file through QSqlTableModel, but while the original table has 2847 records, the view shows only 2755. QSqlTableModel::lastError() does not report any issue.

How can I debug the problem? This is the code I'm using:


QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

db.setDatabaseName(currentDatabase.absoluteFilePat h());

if (!db.open()) {
QMessageBox::critical(this, qApp->tr("Error opening database"),
"Cannot connect to database.\n" + db.lastError().text(), QMessageBox::Cancel);
return;
}

tableModel = new QSqlTableModel(this, db);
ui->tableView->setModel(tableModel);
tableModel->setTable("my_table");
tableModel->select();
ui->tableView->show();

Thanks for any help

d_stranz
24th March 2020, 17:50
Have you verified that an external tool such as DB Browser for SQLite returns the correct count?

bull3t
24th March 2020, 19:45
Have you verified that an external tool such as DB Browser for SQLite returns the correct count?

Yes, already verified

13359

d_stranz
24th March 2020, 21:06
You don't show the context of the code you posted. If it all lives in a single method, then I wonder if it has anything to do with your "db" variable going out of scope at the end of the method? Otherwise, your code seems to be OK.

What does QSqlTableModel::selectStatement() return? Anything suspicious there?