有的数据库表长度是变长的,这时候我们就需要获取查询的表的字段数量了:
QList<QVariantList> data;
QSqlQuery query(db);
QString sql = "SELECT * FROM `table`;";
int ret = query.exec(sql);
if (0 == ret){
return -1; // 查表出错
}
QSqlRecord record;
QVariantList t;
while (query.next()){
record = query.record(); // 获取字段数量
t.clear();
for (int i(0); i < record.count(); ++i){ //
t.append(query.value(i)); //
}
data.append(t);
}