当我把model-> select();在关系之后,模型是空的,当我在关系之前把它放回去时,表格显示正确,但是当我编辑任何单元格时,整行变为空并得到"!"在左边。没有错误。
QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this, db1);
model->setTable("syllabi");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->setRelation(3, QSqlRelation("activity_types", "activity_type_id", "activity_type_name"));
model->setRelation(0, QSqlRelation("teachers", "teacher_id", "teacher_name"));
//model->select();
qDebug() << model->lastError();
ui->tableView->setModel(model);
ui->tableView->setItemDelegate(new QSqlRelationalDelegate(ui->tableView));
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->setColumnHidden(9, true);