
Originally Posted by
caduel
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
// Добавление серийного номера
bool AddSerialNumber::add()
{
while(element -> serialName.size() <= 8)
element
-> serialName
+= (QChar)32;
int modelID = selectModelID();
model.select();
record.setValue("serialNumber", element -> serialName);
record.setValue("secretKey", element -> secret );
record.setValue("security", true);
record.setValue( "modelID", modelID);
model.insertRecord(-1, record);
bool ins = model.submitAll( );
return ins;
}
// Добавление серийного номера
bool AddSerialNumber::add()
{
while(element -> serialName.size() <= 8)
element -> serialName += (QChar)32;
int modelID = selectModelID();
QSqlTableModel model;model.setTable("DeviceList");
model.setEditStrategy(QSqlTableModel::OnManualSubmit);
model.select();
QSqlRecord record = model.record( );
record.setValue("serialNumber", element -> serialName);
record.setValue("secretKey", element -> secret );
record.setValue("security", true);
record.setValue( "modelID", modelID);
model.insertRecord(-1, record);
bool ins = model.submitAll( );
return ins;
}
To copy to clipboard, switch view to plain text mode
This code doesn't works too. submitAll return false
Bookmarks