void MainWindow::on_addButton_clicked() { QSqlRelationalTableModel * model = db->getModel(); int rowCount = model->rowCount(); model->insertRow(rowCount); model->setData(model->index(rowCount, model->fieldIndex("add_date")),QVariant(ui->dateAdd->dateTime())); model->setData(model->index(rowCount, model->fieldIndex("district")),QVariant(ui->district->currentIndex()+1)); if(!model->setData(model->index(rowCount, model->fieldIndex("cert_id")),QVariant(ui->idNumber->text().toInt()),Qt::EditRole)) { qDebug() « model->lastError().databaseText(); // не записывается, QSqlError(-1, "", "") } model->setData(model->index(rowCount, model->fieldIndex("name")),QVariant(ui->name->text())); model->setData(model->index(rowCount, model->fieldIndex("birth_date")),QVariant(ui->birthDate->dateTime())); model->setData(model->index(rowCount, model->fieldIndex("address")),QVariant(ui->address->text())); model->setData(model->index(rowCount, model->fieldIndex("phone")),QVariant(ui->phoneNumber->text())); model->setData(model->index(rowCount, model->fieldIndex("vtekNumber")),ui->vtekNumber->text().toInt()); // не записывается if(!model->submitAll()) { qDebug() « model->lastError().driverText(); // } qDebug() « model->lastError(); // QSqlError(-1, "", "") } 

Two fields are not added to the table (sqlite), instead they are NULL. Both are int, both are taken from QLineEdit.

  • and ui-> idNumber-> text (). toInt () exactly the int returns? Generally, as far as I remember, sqlite is basically on a drum int or not an int there to write, it doesn’t one type check and it seems to store everything with text - aknew
  • Yes, everything returns normally. And in QVariant wrapped, it still does not help. - the name is too short

0