Hi,

I am trying toinsert multiple rows (you can actually call it records) in a database using QSqlTable model but cannot get it working. Can someone please help ?

Following is the code which works.

Qt Code:
  1. for(int i = 0 ; i < n; ++i){ // I want to insert some 10 rows
  2. tableModel.select();
  3. int rc = tableModel.rowCount();
  4. tableModel.insertRow(rc);
  5. rec = tableModel.record(rc);
  6. rec.setValue(QString("nameid"),QVariant(nameIds.at(i)));
  7. rec.setValue(QString("groupid"),QVariant(currentGroupId));
  8. tableModel.setRecord(rc,rec);
  9. tableModel.submitAll();
  10. }
To copy to clipboard, switch view to plain text mode 

I have tired various other methods but all of them are failing. Can someone please suggest the best way to do this?

Thanks a lot.