I have data in a MySQL database which I want to put into a vector in order to do some math on it. It may be that this issue is not specific to QSqlTableModels but rather any QAbstractTableModel, but I'm not sure. Right now, I have
model->QSqlQueryModel::setQuery(q); //model is a QSqlTableModel, q gets 1 column of data
QVector<QVariant> var;
var.reserve(num_rows);
QVariant datum;
QModelIndex idx;
for (i=0; i<num_rows; ++i)
{
idx = model->index(i,0,QModelIndex());
datum = model->data(idx);
var.push_back(datum);
}
Is there any way to improve on this, such as a lower-level copy operation I could use?
EDIT: Following the suggestion of beduin, I tried doing this without the QSqlTableModel but rather by simply iterating through the QSqlQuery. This resulted in significantly slower performance. A copy operation that took 380ms using the above method took 525ms iterating through QSqlQuery, for example, and there were similar differences with other queries.