Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT - How to get values from a single row in QTableView

I have a QTableView with few records, a single row contains four columns. I need to get these 4 index values (name, surname, age, username) in order to delete them in SQLite, so I need these four values to put in the deletion query. I expect to click on an every index of THAT row and get back all the 4 values. How can I do it? Thanks

like image 666
user1336326 Avatar asked Sep 13 '25 16:09

user1336326


1 Answers

I don't see a problem. With QModelIndex you can get any data relative to given model index.

void GuiClass::onTableCellClicked(const QModelIndex &index)
{
    int row = index.row();
    QString name = index.sibling(row, 0).data().toString();
    QString surname = index.sibling(row, 1).data().toString();
    int age = index.sibling(row, 2).data().toInt();
    QString username = index.sibling(row, 3).data().toString();
    ...
}
like image 187
Marek R Avatar answered Sep 16 '25 13:09

Marek R