Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlRelationalTableModel fail update

QSqlRelationalTableModel fail update

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 343 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JukovJ Offline
    JukovJ Offline
    Jukov
    wrote on last edited by
    #1

    My db 0_1528996807029_Снимок экрана от 2018-06-13 18-55-19.jpg
    personnelModel = new QSqlRelationalTableModel(this,db);
    personnelModel->setTable("Personnel");
    currentModel = operationModel;
    currentModel->setRelation(currentModel->fieldIndex("Articul_idArticul"),QSqlRelation("Articul", "idArticul", "Number"));
    // qDebug()<<currentModel->lastError()<<currentModel->query().lastQuery();
    currentModel->setEditStrategy(QSqlRelationalTableModel::OnFieldChange);
    currentModel->select();
    ui->tableView->setModel(currentModel);The data is correctly displayed.
    Qt does not issue errors.
    After selecting in the combobox, the value is not updated, I looked up the database logs and saw it 0_1528996822915_Снимок экранаКонсоль.jpg
    Why does "is null" appear?

    1 Reply Last reply
    0
    • JukovJ Offline
      JukovJ Offline
      Jukov
      wrote on last edited by
      #2

      I found this code in qsqldriver.cpp.

      case WhereStatement:
         {
             const QString tableNamePrefix = tableName.isEmpty()
                 ? QString()
                 : prepareIdentifier(tableName, QSqlDriver::TableName, this) + QLatin1Char('.');
             for (int i = 0; i < rec.count(); ++i) {
                 if (!rec.isGenerated(i))
                     continue;
                 s.append(s.isEmpty() ? QLatin1String("WHERE ") : QLatin1String(" AND "));
                 s.append(tableNamePrefix);
                 s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this));
                 if (rec.isNull(i))
                     s.append(QLatin1String(" IS NULL"));
                 else if (preparedStatement)
                     s.append(QLatin1String(" = ?"));
                 else
                     s.append(QLatin1String(" = ")).append(formatValue(rec.field(i)));
             }
             break;
         }
      

      "IS NULL" appears from the fact that QSqlRecord &rec is null, but when i get record from model it returned normal record

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved