How to forward primary key of selected row QTableView
Hi everyone, i am new in programming world, so please forgive me if i ask stupid question....
I was make my Sql connection to database and use QSqlTableModel to fill QSqlTableView. This is my code:
ui->setupUi(this);
QSqlTableModel *model=new QSqlTableModel(this);
model->setTable("baza");
model->select();
ui->tableRadnici->setModel(model);
ui->tableRadnici->setEditTriggers(QAbstractItemView::NoEditTriggers );
and table "baza":
mysql> describe baza;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | int(14) | NO | PRI | NULL | |
| name | varchar(100) | YES | | NULL | |
| lastname | varchar(100) | YES | | NULL | |
| sector | varchar(100) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
My question is how can i forward id of table row to some function, example if i do double click on field name to forward value of field ID to function
void DialogListaRadnika::on_tableRadnici_activated(cons t QModelIndex &index);
I was looking for solution for about mount, and i fail with that, so please help me.
Thanks
Re: How to forward primary key of selected row QTableView
You have the model index of whatever cell got activated.
You can use the row information to get an index of the first column, which holds your id.
Cheers,
_
Re: How to forward primary key of selected row QTableView
Thanks for quick replay :)
I was solve this problem by this syntax
ui->tableRadnici->model()->data(ui->tableRadnici->model()->index(index.row(),0)).toString();
where ui->tableRadnici is my QTableView in my form.
Cheers :)