title: Is there any cleaner way to do this? (Prepared SQL queries in Qt C++)
body: <p>I'm using QSqlQuery::prepare() and ::addBindValue() for my queries in a Qt project I'm working on. There's a lot of repeated code and though I think that's the "right" way, I wanted to make sure. Perhaps someone has alternative ideas? Example:</p>
  
  <pre><code>QSqlQuery newQuery;
  newQuery.prepare("INSERT INTO table "
                   "(foo,bar,baz,"
                   "herp,derp,biggerp,"
                   "alpha,beta,gamma,"
                   "etc) VALUES "
                   "(?,?,?,"
                   "?,?,?,"
                   "?,?,?,"
                   "?)");
  newQuery.addBindValue(this-&gt;ui-&gt;txtFoo-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtBar-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtBaz-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtHerp-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtDerp-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtBiggerp-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtAlpha-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtBeta-&gt;text());
  newQuery.addBindValue(this-&gt;ui-&gt;txtGamma-&gt;itemText(0));
  newQuery.addBindValue(this-&gt;ui-&gt;txtEtc-&gt;text());
  newQuery.exec();
  </code></pre>
  
  <p>You can see there's a bunch of the same "newQuery.addBindValue(this->ui->__________" over and over. Is this the 'best' way to go about it?</p>
  
  <p>Also, I asked in #qt on freenode the other night but didn't get a definitive answer; will the above (::prepare with ::addBindValue) protect agains SQL injection? The reference didn't really say. </p>