Maybe something like this:
list << QPair<QString, QVariant>("fld1", 10);
list << QPair<QString, QVariant>("fld2", "xxx");
list << QPair<QString, QVariant>("fld3", "2005-01-01");
//...
foreach(QPair<QString, QVariant> item, list){
rec.setValue(item.first, item.second);
}
// ...
QList< QPair< QString, QVariant > >list;
list << QPair<QString, QVariant>("fld1", 10);
list << QPair<QString, QVariant>("fld2", "xxx");
list << QPair<QString, QVariant>("fld3", "2005-01-01");
//...
QSqlRecord rec = model->record();
foreach(QPair<QString, QVariant> item, list){
rec.setValue(item.first, item.second);
}
// ...
To copy to clipboard, switch view to plain text mode
Of course you can construct the list in any way you want. You could use a QMap instead and have something like this:
QMap<QString, QVariant> map;
map["fld1"] = 10;
map["fld2"] = "xxx";
map["fld3"] = "2005-01-01";
//...
record.setValue(key, map[key]);
}
//...
QMap<QString, QVariant> map;
map["fld1"] = 10;
map["fld2"] = "xxx";
map["fld3"] = "2005-01-01";
//...
foreach(QString key, map.keys()){
record.setValue(key, map[key]);
}
//...
To copy to clipboard, switch view to plain text mode
Bookmarks