我使用QSqlQuery类查询sqlite db,如下所示:
QSqlQuery query("SELECT country FROM artist");
while (query.next()) {
QString country = query.value(0).toString();
doSomething(country);
}有没有办法直接从QSqlLite类中获取QVariants的向量?如下所示:
QSqlQuery query("SELECT country FROM artist");
while (query.next()) {
std::vector< QVariant > allFields;
allFields.push_back( query.value(0) );
allFields.push_back( query.value(1) );
allFields.push_back( query.value(2) );
doSomething(allFields);
}发布于 2010-12-20 20:47:50
使用boundValues:
QList<QVariant> allFields = query.boundValues().values();附言:我不会在Qt中使用std容器。Qt-containers有一个主要的优势--隐式共享。我建议使用QList而不是std::vector
https://stackoverflow.com/questions/4489636
复制相似问题