Looks like the edit call causes the malfunction, probably because the "id" field is set to "0" instead of the proper index.
I changed the addRow() method and it works fine now:
void Table::addRow()
{
int row = proxyModel->sourceModel()->rowCount();
proxyModel->sourceModel()->insertRow(row);
QModelIndex idx
= proxyModel
->sourceModel
()->index
(row,
1);
if (idx.isValid())
{
proxyModel->sourceModel()->setData(idx.sibling(idx.row(), 0), row); // added here
idx = proxyModel->mapFromSource(idx);
setCurrentIndex(idx);
edit(idx);
}
}
void Table::addRow()
{
int row = proxyModel->sourceModel()->rowCount();
proxyModel->sourceModel()->insertRow(row);
QModelIndex idx = proxyModel->sourceModel()->index(row, 1);
if (idx.isValid())
{
proxyModel->sourceModel()->setData(idx.sibling(idx.row(), 0), row); // added here
idx = proxyModel->mapFromSource(idx);
setCurrentIndex(idx);
edit(idx);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks