query.exec(QString("select d.doc_id, c.feat_num, distinct_lem_cnt, count(*) from romip_legal_queries_morfo as a, et1doc_feats as b, et2feats as c, et2docs as d where line_no = %1 and a.feat_id = c.feat_id and c.feat_num = b.feat_num and b.doc_num = d.doc_num group by doc_id, feat_num order by doc_id;").arg(queries[i].id));while(query.next()){ count = query.value(3).toInt(); DoSomeThing();}