Qtableview + proxy model + sqltablemodel problem getting correct data



  • Hi, I'm trying to get the value from the selected cell of a QTableView.
    The table has a QSqlTableModel and a QSortFilterProxyModel.

    If I use the signal doubleClicked(const QModelIndex &index) (it is a tableView signal), it works as expected because I use the correct index of the row.

    The problems starts when I use a simple push button to get the data from the selected cell. In fact, if the rows are sorted clicking on the header, even if the row order is changed I continue to get same row and column number and so the data is incorrect.

    here some code from the on_pushButton_clicked() signal:

    @
    QModelIndexList list = ui->tableView->selectionModel()->selectedIndexes();
    QModelIndex index = filterProxyModel->mapToSource(list.at(0));
    bool data = ui->tableView->model()->data(ui->tableView->model()->index(index.row(),4)).toBool();
    @

    I think I should take the data using the proxy model, but I can't find the correct syntax.

    Help me please!
    Thanks


Log in to reply
 

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