Line 4 creates a new selection model rather than fetching the model that is already associated with the view. Line 5 does not do what you think it does: it deselects everything, it does not delete selected data. You want something like this (I haven't tested it so please forgive minor glitches):
void Loader::removeChannelFromTable()
{
QMessageBox::information(this,tr
(""),tr
("Slot working?") );
// to make sure slot is being run.
// code to get list of selected rows
QModelIndexList rowList = selected->selectedRows();
// code to delete these model indexes from the model
model->removeRow(roxIndex.row(), rowIndex.parent());
}
}
void Loader::removeChannelFromTable()
{
QMessageBox::information(this,tr(""),tr("Slot working?") ); // to make sure slot is being run.
// code to get list of selected rows
QItemSelectionModel *selected = channelsView->selectionModel();
QModelIndexList rowList = selected->selectedRows();
// code to delete these model indexes from the model
foreach(QModelIndex rowIndex, rowList) {
model->removeRow(roxIndex.row(), rowIndex.parent());
}
}
To copy to clipboard, switch view to plain text mode
You might also consider using QAbstractItemView::setSelectionBehavior() and QAbstractItemView::setSelectionMode() on the view so the user selects whole rows etc.
Bookmarks