Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] - return primary key - QSqlQueryModel - QTableView
Forum Updated to NodeBB v4.3 + New Features

[solved] - return primary key - QSqlQueryModel - QTableView

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    angelicaP
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arsinte_andrei
      wrote on last edited by
      #2

      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);@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        angelicaP
        wrote on last edited by
        #3

        thanks, that helped.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved