int Engine::insertGoodItem(QString name, int type, int price){ QSqlRecord record = modelGoods->record(); record.setValue( "name", name); record.setValue( "type", type); record.setValue( "price", price); int row=modelGoods->rowCount(); modelGoods->insertRow(row); bool ok = modelGoods->setRecord(row, record); modelGoods->submitAll(); return row;}
void Milano::on_addButton_clicked(){ int row = engine.insertGoodItem(tr("лалала"), 0, 0); QModelIndex index = engine.modelGoods->index(row, 1); ui.tableGoodsView->setCurrentIndex( index ); ui.tableGoodsView->setFocus();}
C++ (Qt)for (int i = 0, count = modelGoods->rowCount(); i < count; i++) { if (engine.modelGoods->index(row, {ID}).data (Qt::DisplayRole) == "Some value") { //Select row break; }}