PDA

View Full Version : How to get list of selected rows during multiple selection in Qtableview?



allulks
14th November 2015, 07:53
I have the data in Qtableview, where my task is, when ever I do multiple
selection of rows I want the content of all selected rows. or at least I
would like to know what are the row numbers I have selected.

I am trying with this code but I am getting 'Zero' every time even though I don't select any row.

If I give Printf() after the right curly braces it's printing 'zero ' every time.

and If I print() it before right curly braces nothing is getting printed

ui->xvalue->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
ui->xvalue->setSelectionBehavior(QAbstractItemView::SelectRows );
ui->xvalue->show(); QModelIndexList indexList = ui->xvalue->selectionModel()->selectedIndexes(); int row;
foreach (QModelIndex index, indexList){

row = index.row(); }
printf("\n%d\n",row);


I even tried this but no use I am not getting the answer

QItemSelectionModel* selectionModel =this-> ui->xvalue->selectionModel();
QModelIndexList selected = selectionModel->selectedIndexes(); i
nt num;
for(int i=0; i< selected.count();i++)
{
QModelIndex index = selected.at(i);
qDebug()<< index.row();
num = index.row();

printf("selected row is %d", num);
}