int row = model->rowCount(); int id = model->rowCount()==0 ? 1 : model->record(model->rowCount()-1).value("id").toInt()+1; model->insertRows(row,1); model->setData(model->index(row,0),id); model->setData(model->index(row,2),4);
model->submitAll(); model->select();
class RecipeIngredientsModel : public QSqlRelationalTableModel { Q_OBJECTpublic: RecipeIngredientsModel(QObject *parent = 0): QSqlRelationalTableModel(parent) {} QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const { QVariant value =QSqlQueryModel::data(index, role); switch (role) { case Qt::SizeHintRole: // Размер ячейки return QSize(300, 10); } return value; }};