title: QML TableView get data from specific cell (selected row + specific column)
body: <p>I have QML <code>TableView</code> with <code>QSqlQueryModel</code>. I need to select any row and get data from every column of table to separate <code>TextField</code>.</p>
  
  <p>Here is abonentstable.h:</p>
  
  <pre><code>#pragma once
  
  #include &lt;QObject&gt;
  #include &lt;QSqlQueryModel&gt;
  
  class AbonentsSqlModel : public QSqlQueryModel
  {
      Q_OBJECT
  
  public:
      explicit AbonentsSqlModel(QObject *parent = 0);
  
      void setQuery(const QString &amp;query, const QSqlDatabase &amp;db = QSqlDatabase());
      QVariant data(const QModelIndex &amp;index, int role) const;
      QHash&lt;int, QByteArray&gt; roleNames() const { return m_roleNames; }
  
  private:
      void generateRoleNames();
      QHash&lt;int, QByteArray&gt; m_roleNames;
  };
  </code></pre>
  
  <p>abonentstable.cpp:</p>
  
  <pre><code>#include "abonentstable.h"
  
  #include &lt;QSqlRecord&gt;
  #include &lt;QSqlField&gt;
  
  AbonentsSqlModel::AbonentsSqlModel(QObject *parent) : QSqlQueryModel(parent)
  {
      QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
      db.setDatabaseName("data_base.sqlite");
      db.open();
  }
  
  void AbonentsSqlModel::setQuery(const QString &amp;query, const QSqlDatabase &amp;db)
  {
      QSqlQueryModel::setQuery(query, db);
      generateRoleNames();
  }
  
  void AbonentsSqlModel::generateRoleNames()
  {
      m_roleNames.clear();
      for( int i = 0; i &lt; record().count(); i ++) {
          m_roleNames.insert(Qt::UserRole + i + 1, record().fieldName(i).toUtf8());
      }
  }
  
  QVariant AbonentsSqlModel::data(const QModelIndex &amp;index, int role) const
  {
      QVariant value;
  
      if(role &lt; Qt::UserRole) {
          value = QSqlQueryModel::data(index, role);
      }
  
      else {
          int columnIdx = role - Qt::UserRole - 1;
          QModelIndex modelIndex = this-&gt;index(index.row(), columnIdx);
          value = QSqlQueryModel::data(modelIndex, Qt::DisplayRole);
      }
  
      return value;
  }
  </code></pre>
  
  <p>Table.qml:</p>
  
  <pre><code>TableView {
      id: table
  
      model: abonents
  
      ....
  
      TableViewColumn {
          delegate: Text {
              text: " " + model.name + " " + model.surname
              font.pointSize: 20
          }    
          width: 575
      }
  
      TableViewColumn {
          delegate: Text {
              text: " " + model.phone
              font.pointSize: 20
          }    
          width: 575
      }
  
      TableViewColumn {
          delegate: Text {
              text: " " + model.ip_address
              font.pointSize: 20
          }    
          width: 525
      }
  }
  </code></pre>
  
  <p>And some text fields:</p>
  
  <pre><code>TextField {
      id:  leftText
  }
  
  TextField {
       id:  centerText
  }
  
  TextField {
      id:  rightText
  }
  </code></pre>
  
  <p>This sqlite table has 4 columns, and I need to get data from selected row to those text fields: 2 columns to left, 1 to center and 1 to right.</p>