Search code examples
qtsqliteqtableviewqmodelindex

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


Solution

  • 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();
        ...
    }