Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableView : how to select data?

I have a hopefully simple question, I will explain it by showing you a screenshot and a snippet of my source code:

enter image description here

I want to select a cell like wo_forename or wo_name, at the moment I can get this data from this cell. What I want is the following : if you select the forename or whatever in the row, my programm needs to know the wo_id. In the text labels on the left side, I show the selected forename and lastname.

void adminUserData::on_tableView_activated(const QModelIndex &index)
{
QString val;

val = ui->tableView->model()->data(index).toString();
QSqlQuery qry;
qry.prepare("SELECT * FROM worker WHERE wo_id='"+val+"'");
if (qry.exec())
{
   while (qry.next())
   {
      // ui->label_test->setText(qry.value(1).toString());
       val=index.column();
       ui->label_test->setText(val);
       ui->label_test2->setText(qry.value(2).toString());
   }
}
}

How to change the code in order to get the id ?

like image 246
Frederik Ubben Avatar asked Aug 08 '26 15:08

Frederik Ubben


1 Answers

QModelIndex first = ui->tableView->model()->index(index.row(), 0);

If i use this as "new" index it works =)

like image 73
Frederik Ubben Avatar answered Aug 10 '26 08:08

Frederik Ubben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!