[solved] - return primary key - QSqlQueryModel - QTableView
-
hi,
I have a tableView populated by a QSqlQueryModel. I would like to know if there is any chance to return the primary key from the table where the record is located. I would like to select a row in the tableView and return the selected primary key. I tried something like below, which returns the index of my selected row, but not the primary key of the record.
@void formSelect::on_tableView_clicked(const QModelIndex &index)
{
int rowIndex;
rowIndex= index.row;
}@I know the QSqlTableModel has the posibility to return the primary key, but for editable protection I would like not to use the QSqlTableModel.
how could this be achieved?
thank you for your time. -
like that I get the id from a table view
@
void formSelect::on_tableView_clicked(const QModelIndex &index){
int rowIndex;
rowIndex= index.row;
QString myIdS = ui->tableView->model()->data(ui->tableView->model()->index(rowIndex,0)).toString();
int myIdI = ui->tableView->model()->data(ui->tableView->model()->index(rowIndex,0)).toInt();
}@not to be afraid about editing it do
@ui->tableView->setEditStrategy(QSqlTableModel::OnManualSubmit);@ -
thanks, that helped.