Cannot see the header labels SQL
Dear Friends
I am trying to generate a table with the code below. But I cannot see the header labels in the view. Only a blank page is coming. Please give me some suggestion. Thanks sujan
Code:
model->setTable("student");
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("studentID"));
model->setHeaderData(1, Qt::Horizontal, tr("Name"));
model->setHeaderData(2, Qt::Horizontal, tr("FirstName"));
model->database().transaction();
qDebug() << model->database().commit();
model->submitAll();
view->setModel(model);
view->show()
Re: Cannot see the header labels SQL
Where did you set up the database connection? And for a QSqlQueryModel you have to perform a query. If you want to set a table use QSqlTableModel.
Re: Cannot see the header labels SQL
Your sample code won't compile for the reason pointed out by Lykurg. Once that is corrected the code works fine for me.
You should get into the habit of checking return values and, when they indicate errors, QSqlDatabase::lastError() or QSqlQueryModel::lastError().
QSqlTableModel::select() returns a true/false indication you are ignoring.