Quote Originally Posted by caduel View Post
looks like the order of the fields is not as you expected (seems like column 1 is "security"; you can check by displaying the QSqlTableModel in a QTableView).

How about this approach:
populate (access columns by name) a QSqlRecord (you get an empty one with record()) and insert it with QSqlTableModel::insertRecord()
This way your code does not depend on the order of the columns in the table.

HTH
Qt Code:
  1. // Добавление серийного номера
  2. bool AddSerialNumber::add()
  3. {
  4. while(element -> serialName.size() <= 8)
  5. element -> serialName += (QChar)32;
  6.  
  7. int modelID = selectModelID();
  8. QSqlTableModel model;model.setTable("DeviceList");
  9. model.setEditStrategy(QSqlTableModel::OnManualSubmit);
  10. model.select();
  11. QSqlRecord record = model.record( );
  12. record.setValue("serialNumber", element -> serialName);
  13. record.setValue("secretKey", element -> secret );
  14. record.setValue("security", true);
  15. record.setValue( "modelID", modelID);
  16. model.insertRecord(-1, record);
  17. bool ins = model.submitAll( );
  18.  
  19. return ins;
  20. }
To copy to clipboard, switch view to plain text mode 

This code doesn't works too. submitAll return false