Strangely, it returns "QSqlQuery::value: not positioned on a valid record" error when I press to the delete key.
My delete function:
{
model->removeRow(index.row());
model->submitAll();
}
void lessons::deleteLesson(QModelIndex index)
{
QSqlTableModel *model = this->lessonsTable();
model->removeRow(index.row());
model->submitAll();
}
To copy to clipboard, switch view to plain text mode
lessonsTable function:
{
model->setTable("lessons");
model->select();
model->removeColumn(0); // Don't show the ID
model->setHeaderData(0, Qt::Horizontal, "Name");
model->setHeaderData(1, Qt::Horizontal, "Teacher");
return model;
}
QSqlTableModel* lessons::lessonsTable()
{
QSqlTableModel *model = new QSqlTableModel;
model->setTable("lessons");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->removeColumn(0); // Don't show the ID
model->setHeaderData(0, Qt::Horizontal, "Name");
model->setHeaderData(1, Qt::Horizontal, "Teacher");
return model;
}
To copy to clipboard, switch view to plain text mode
And where I call the function:
void osman::on_pushButton_del_lesson_clicked()
{
lsn.deleteLesson(ui->tableView_lessons->currentIndex());
}
void osman::on_pushButton_del_lesson_clicked()
{
lsn.deleteLesson(ui->tableView_lessons->currentIndex());
}
To copy to clipboard, switch view to plain text mode
Bookmarks