model->setTable("subjects");
model->select();
model->removeColumn(0); // don't show the ID
ui->tableView->setModel(model);
model = new QSqlTableModel(this, db1);
model->setTable("subjects");
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->removeColumn(0); // don't show the ID
ui->tableView->setModel(model);
To copy to clipboard, switch view to plain text mode
Inserting:
model->insertRow(0);
model->insertRow(0);
To copy to clipboard, switch view to plain text mode
Deleting:
QModelIndexList selection = ui->tableView->selectionModel()->selectedRows();
if (selection.count())
{
for (int i = 0; i < selection.count(); i++)
{
qDebug() << index.row();
qDebug() << model->removeRow(selection.at(i).row());
model->select();
qDebug() << model->lastError();
//model->submitAll();
}
//model1->submitAll();
}
QModelIndexList selection = ui->tableView->selectionModel()->selectedRows();
if (selection.count())
{
for (int i = 0; i < selection.count(); i++)
{
QModelIndex index = selection.at(i);
qDebug() << index.row();
qDebug() << model->removeRow(selection.at(i).row());
model->select();
qDebug() << model->lastError();
//model->submitAll();
}
//model1->submitAll();
}
To copy to clipboard, switch view to plain text mode
So, the table displays correctly.
When I edit a cell, the row gets empty and shows !, like it was deleted. Nothing changes in DB.
When I delete a row with algorithm above, removeRow returns true, the table view blinks like it's re-rendering, but nothing changes.
When I insert a row, edit it, it gets empty and shows !, BUT it appears in DB and it's in the table when I reopen the app.
When I un-comment model->submitAll(); nothing changes.
Any ideas?
Bookmarks