Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, June 2007
best practices for QSqlQuery


Message 1 in thread

I want to create a list of objets with the data returned in a QSqlQuery

supose qQuery is QSqlQuery

Person* person;
while(qQuery.next()){
    person = new Person(qQuery);
    persons.push_back(person);
}


adn my person constructor is l

Person::Person(QSqlQuery query){
  _id = query.value(0).toString();
  // SETUP OTHER ATTS
}

the problem of this approach is that postion is not guaranted to be in
a especific order and

Person::Person(QSqlQuery query){
  _id = query.value(query.record().indexOf("_id")).toString();
  //SETUP OTHER ATTS
}

is correct call query.record().indexOf(fieldName) each time

or is better get all the values one a pass it to the constructor


int idPos = qQuery.record().indexOf("_id");

Person* person;
while(qQuery.next()){
    person = new Person(qQuery,idPos);
    persons.push_back(person);
}

Other ideas for efficiency fill a list of objets based on a QSqlQuery

thanks in advance

-- 
 [ signature omitted ]