setHorizontalHeaderLabels requires a QStringList, furthermore make sure you set the labels after the model is populated. And I guess you have to set the labels everytime you change the query.
EDIT: or make it, like the documentation tells:
model->setQuery("SELECT name, salary FROM employee");
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
view->setModel(model);
view->show();
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT name, salary FROM employee");
model->setHeaderData(0, Qt::Horizontal, tr("Name"));
model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
QTableView *view = new QTableView;
view->setModel(model);
view->show();
To copy to clipboard, switch view to plain text mode
Bookmarks