QtSQL how to read record as QMap
is there a quick way to r开发者_开发问答ead 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.
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.
精彩评论