title: How to get the executed SQL statement associated with QSqlTableModel::setData()?
body: <p>I am inserting/updating a database table from a Qt application using <code>QSqlTableModel</code>methods <code>setData</code>, <code>submitAll</code> and <code>commit</code>.
  For logging purposes, I need to record the corresponding SQL statements.
  How can I do that?
  (I am looking at <code>QSqlTableModel::query()</code> but seems as if it only returns SELECTs)</p>
  
  <p>Here is a simplified version of what I am doing.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>QSqlTableModel *_dataTableModel = qobject_cast&lt;QSqlTableModel*&gt;(dataTableView-&gt;model());
  _dataTableModel-&gt;setData(item, value);
  _dataTableModel-&gt;database().transaction();
  _dataTableModel-&gt;submitAll();
  _dataTableModel-&gt;database().commit()
  QSqlQuery _currentQuery = _dataTableModel-&gt;query();
  qDebug() &lt;&lt; _currentQuery.lastQuery();
  </code></pre>
  
  <p>The last line always prints a SELECT, even when I do an update or an insert.</p>
  
  <hr>
  
  <h2>update</h2>
  
  <p>Here is a self-sufficient code snippet. The setup is that, I have a UI with a <code>QTableView</code> and a <code>QPushButton</code>. <code>clicked()</code> signal of push button is captured in <code>addNewRow()</code> slot and a arbitrary value is inserted to the first cell. 
  I am printing the result of the <code>lastQuery()</code> expecting it to be the insert statement but it is a SELECT statement for the given table. What am I doing wrong?</p>
  
  <p><strong>main.cpp</strong></p>
  
  <pre class="lang-cpp prettyprint-override"><code>{
      QApplication a(argc, argv);
      test1 w;
      // connect to and open database
      w.setDataTable("MY_TEST_TABLE");
      w.show();
      return a.exec();
  }
  </code></pre>
  
  <p><strong>test1.h</strong></p>
  
  <pre class="lang-cpp prettyprint-override"><code>public:
      void setDataTable(QString dataTableName);
  
  private slots:
      void addNewRow();
  </code></pre>
  
  <p><strong>test1.cpp</strong></p>
  
  <pre class="lang-cpp prettyprint-override"><code>void test1::setDataTable( QString dataTableName )
  {
      QSqlTableModel *tableModel = new QSqlTableModel(); 
      tableModel-&gt;setTable(dataTableName);
      tableModel-&gt;select();   
      ui.tableView-&gt;setModel(tableModel);
  }
  
  void test1::addNewRow()
  {
      QSqlTableModel *tableModel = qobject_cast&lt;QSqlTableModel*&gt;(ui.tableView-&gt;model());
      if(!tableModel-&gt;insertRow(tableModel-&gt;rowCount())) {
              return;
      }       
      tableModel-&gt;setData(tableModel-&gt;index(0, 0), QVariant("123345")); 
      tableModel-&gt;database().transaction(); 
      if(!tableModel-&gt;submitAll()) {
              return;
      }  
      if (!tableModel-&gt;database().commit()) {                                          
              return;
      }     
      qDebug() &lt;&lt; tableModel-&gt;query().lastQuery();
  } 
  </code></pre>