model.setTable("poems");
model.
setRelation(3,
QSqlRelation( "authors",
"author_id",
"name"));
model.setHeaderData(0, Qt::Horizontal, t("ID"));
model.setHeaderData(1, Qt::Horizontal, t("Title"));
model.setHeaderData(2, Qt::Horizontal, t("Year"));
model.setHeaderData(3, Qt::Horizontal, t("Author"));
model.select();
table_view->setModel(model);
QSqlRelationalTableModel model;
model.setEditStrategy(QSqlTableModel::OnManualSubmit);
model.setTable("poems");
model.setRelation(3, QSqlRelation( "authors", "author_id", "name"));
model.setHeaderData(0, Qt::Horizontal, t("ID"));
model.setHeaderData(1, Qt::Horizontal, t("Title"));
model.setHeaderData(2, Qt::Horizontal, t("Year"));
model.setHeaderData(3, Qt::Horizontal, t("Author"));
model.select();
QTableView table_view;
table_view->setModel(model);
table_view->setItemDelegate(new QSqlRelationalDelegate(table_view));
To copy to clipboard, switch view to plain text mode
Bookmarks