Extract data from QModelIndex



  • I created a QTableWidget, and now I would like extract the indexes (so, can be more than one) of the currently selected rows, so I can process them later. From my attempt, where tracklist is my QTablwWidget

        QItemSelectionModel *select = tracklist->selectionModel();
        QModelIndexList phi = select->selectedRows();
    
        QList<QModelIndex>::iterator x;
        for (x = phi.begin(); x != phi.end(); ++x)
            {
                qDebug() << *x ;
            }
    

    The output is:

    QModelIndex(0,0,0x0,QTableModel(0x2031bb98))
    QModelIndex(1,0,0x0,QTableModel(0x2031bb98))
    QModelIndex(2,0,0x0,QTableModel(0x2031bb98))
    QModelIndex(3,0,0x0,QTableModel(0x2031bb98))
    QModelIndex(4,0,0x0,QTableModel(0x2031bb98))
    QModelIndex(5,0,0x0,QTableModel(0x2031bb98))
    

    What interests me, is the first term between the round brackets (0,1,2,3,4,5). There is a way to extract this value?

    Thank you in advance


  • Qt Champions 2017



  • @mrjj yes, thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.