title: Access all fields of an SQLite query record result?
body: <p>I'm learning <code>Sqlite</code> in Qt but have run into a problem accessing record values returned by a <code>QSqlQuery</code>.</p>
  
  <p>The details are below but the gist is: I get a <code>QSqlRecord</code> back from a query and want to access all fields of the record but <code>QSqlRecord.count</code> is reporting only one column when there clearly are two (in the example they are <em>id</em> and <em>keyword</em>).</p>
  
  <p>Am I misunderstanding SQLite and what a query does, or is this a problem with how I am trying to access the records?</p>
  
  <hr>
  
  <p><strong>This is my schema:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/MIu4J.png" alt="enter image description here"></p>
  
  <p><strong>This is my test data:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/9CXVO.png" alt="enter image description here"></p>
  
  <p><strong>Full code:</strong></p>
  
  <pre><code>void MainWindow::on_addKeywordBtn_clicked()
  {
  
      // find a matching keyword
      QSqlQuery query(db);
      query.prepare("SELECT keyword FROM keywords WHERE keyword = ?");
      query.addBindValue(QString("blue"));
      query.exec();
  
  
      while (query.next()) {
          QString k = query.value(0).toString();
          qDebug() &lt;&lt; "found" &lt;&lt; k;
  
          QSqlRecord rec = query.record();
  
          qDebug() &lt;&lt; "Number of columns: " &lt;&lt; rec.count();
  
          int idIndex = rec.indexOf("id");
          int keywordIndex = rec.indexOf("keyword");
           qDebug() &lt;&lt; query.value(idIndex).toString() &lt;&lt; query.value(keywordIndex).toString();
  
      }
  }
  </code></pre>
  
  <p>Console output:</p>
  
  <pre><code>found "blue" 
  Number of columns:  1 
  QSqlQuery::value: not positioned on a valid record
  "" "blue" 
  </code></pre>