I am playing with Qt (I am a beginner), and trying to show a table’s data in a QTableView.
So far I have this:
ui->setupUi(this);
QSqlDatabase db;
db=QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (db.open())
qDebug() << "success";
else
qDebug() << "failed";
QSqlTableModel model;
model.setTable("names");
model.select();
qDebug() << model.rowCount();
ui->tableView->setModel(&model);
The problem is that, the model does get the data(2 rows), but the QTableView does now show it.
Any clues what is wrong here?
Looking at your code it could be your
modelobject is going out of scope. Make these few changes, hopefully they will get your issue corrected.