title: QSqlRelationalModel model/view update after changes
body: <p>I've got a problem with updating model/view after changes.</p>
  
  <p>To explain better what I mean I wrote a simple example with SQLite.</p>
  
  <p>So the main.cpp file:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  
  #include "MainForm.h"
  
  void createConnection()
  {
      QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
      db.setDatabaseName("deptemployee.dat");
      if (!db.open()) {
          QMessageBox::information(0, QObject::tr("Database Error"), db.lastError().text());
          db.close();
          return;
      }
  }
  
  void createFakeData()
  {
      QSqlQuery query;
      query.exec("DROP TABLE Department");
      query.exec("DROP TABLE Employee");
  
      query.exec("CREATE TABLE Department(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(40) NOT NULL)");
      query.exec("CREATE TABLE Employee(id INTEGER PRIMARY KEY AUTOINCREMENT, departmentid INTEGER NOT NULL, FOREIGN KEY (departmentid) REFERENCES Department)");
  
      query.exec("INSERT INTO Department(name) VALUES('SomeDepartment')");
      query.exec("INSERT INTO Department(name) VALUES('AnotherDepartment')");
  
      query.exec("INSERT INTO Employee(departmentid) VALUES(1)");
      query.exec("INSERT INTO Employee(departmentid) VALUES(2)");
  }
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
  
      createConnection();
      createFakeData();
  
      MainForm form;
      form.resize(500, 600);
      form.show();
  
      return a.exec();
  }
  </code></pre>
  
  <p>The MainForm.h file:</p>
  
  <pre><code>#pragma once
  
  #include &lt;QWidget&gt;
  #include &lt;QObject&gt;
  
  #include &lt;QtWidgets&gt;
  #include &lt;QtSql&gt;
  
  enum {
      Employee_Id = 0,
      Employee_DepartmentId = 1
  };
  
  class MainForm : public QWidget
  {
      Q_OBJECT
  
  public:
      MainForm()
      {
          model = new QSqlRelationalTableModel(this);
          model-&gt;setTable("Employee");
          model-&gt;setRelation(Employee_DepartmentId, QSqlRelation("Department", "id", "name"));
          model-&gt;select();
  
          view = new QTableView;
          view-&gt;setModel(model);
          view-&gt;setItemDelegate(new QSqlRelationalDelegate(this));
  
          addButton = new QPushButton("Add");
          connect(addButton, SIGNAL(clicked()), SLOT(addButtonClicked()));
  
          QVBoxLayout* mainLayout = new QVBoxLayout;
          mainLayout-&gt;addWidget(view);
          mainLayout-&gt;addWidget(addButton);
          setLayout(mainLayout);
  
          model-&gt;select();
      }
  
  private slots:
      void addButtonClicked()
      {
          int row = model-&gt;rowCount();
          model-&gt;insertRow(row);
          QModelIndex index = model-&gt;index(row, Employee_DepartmentId);
          view-&gt;setCurrentIndex(index);
          view-&gt;edit(index);
      }
  
  private:
      QPushButton*                addButton;
      QTableView*                 view;
      QSqlRelationalTableModel*   model;
  };
  </code></pre>
  
  <p>So about bug... After editing the cell which contains foreign keys the displayed value becomes wrong. So for example after change of department it is displayed as integer rather than string. Why? Is it Qt bug?</p>
  
  <p>After adding a new row the same problem.</p>