开发者

QtSQL how to read record as QMap

开发者 https://www.devze.com 2023-02-23 00:17 出处:网络
is there a quick way to r开发者_开发问答ead record from query as a QMap<QString,QVariant> or similar type ?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消