2

is there a quick way to read record from query as a QMap<QString,QVariant> or similar type ?

Or maybe You could tell me how to access the list of columns in current record ?

Thanks.

Ronny Brendel
  • 4,777
  • 5
  • 35
  • 55

1 Answers1

1

I don't think there is such method. But You can construct QMap object containing all columns like this:

QString sql = "SELECT * FROM xxx WHERE id = x";
query.exec(sql);
QSqlRecord record = query.record();
query.next();

QMap<QString,QVariant> params;
for (int i=0; i<record.count(); ++i) {
    params.insert(record.fieldName(i++), query.value(i));
}

As you can see QSqlRecord provides access to information about columns and so on.

Sebastian Dusza
  • 2,470
  • 2
  • 30
  • 54