我尝试从sqlite获取数据,我需要将n-th和(n 1( - 从查询到myList(列表上的每个项目都包含n-(TH和(n 1( - 第三行(这是我到目前为止的代码
QSqlQuery query("SELECT country FROM artist");
while(query.next()){
m_datalist.append(new DataObject(query.value("country"),this_field _should_be_the_next_row_with_value contry));
}
如何同时从查询中获得n-th-th和(n 1( -
只需将上一个值保留在变量中:
QString previous = ""; // whatever the first one should be
while (query.next()) {
QString nth = query.value(...);
...append(nth, previous);
previous = nth;
}
添加计数器变量:
int i=0;
while(query.next()){
if(i==n || i==n+1)
{
m_datalist.append(...);
}
i++;
}
或者您只能选择所需的记录:
QSqlQuery query("SELECT country FROM artist LIMIT 2 OFFSET "+QString::number(n));