I am using QStandardItemModel inside a QTableView . Here I have two buttons and a QTableView inside my main window. Lines will change inside the model. Two buttons for adding / deleting a line (test script).
Adding a line to the model works, the slot for the ADD button : -
void MainWindow::on_pushButton_clicked() { model->insertRow(model->rowCount()); }
But my program crashes when I delete a line from the model, slot for Delete button : -
void MainWindow::on_pushButton_2_clicked() { QModelIndexList indexes = ui->tableView->selectionModel()->selection().indexes(); QModelIndex index = indexes.at(0); model->removeRows(index.row(),1); }
Please suggest what I need to change in my code to remove the job.
Edit: ----
It worked.
QModelIndex currentIndex = ui->tableView->selectionModel()->currentIndex(); model->removeRow(currentIndex.row());
source share