这是从 QSqlRelationTableModel 派生的 QLSqlTableModel 类中的成员函数,已为调试而修改:
void QLSqlTableModel::setQLData(int row, int column, QVariant value){
QModelIndex qmi = index(row, column);
QVariant originalVal = qmi.data();
bool isSet = setData(qmi, value);
QVariant newVal = qmi.data();
}
当我通过调试器运行它时,我的值是:
value = "B"
originalValue = "A"
isSet = true
newVal = "A"
出于某种原因,即使 setData() 返回 true,它实际上并没有设置新的数据值。我的表实现是:
QLSqlTableModel *model = new QLSqlTableModel(NULL, db);
model->setTable("tableName");
model->setEditStrategy(QSqlRelationalTableModel::OnManualSubmit);
model->generateRoleNames();
model->select();