title: How to update QAbstractItemModel view when a Data is updated
body: <p>I use the <code>Qt example for QAbstractItemModel</code> and I try to update an <code>Item</code> to a given <code>index</code>.</p>
  
  <p>I tried to use <code>emit DataChanged</code>but it doesn't work, <strong>the view is not updated</strong>.</p>
  
  <p>Here is an example:</p>
  
  <p><strong>What I want</strong>: When you click on the button, it will <strong>update Data at index 0</strong>, the <code>type</code> of the animal will be changed, it will become a <strong>Lion</strong>. </p>
  
  <pre><code>#include &lt;QAbstractListModel&gt;
  #include &lt;QStringList&gt;
  #include &lt;qqmlcontext.h&gt;
  //![0]
  class Animal
  {
  public:
      Animal(const QString &amp;type, const QString &amp;size);
  //![0]
  
      QString type() const;
      QString size() const;
  
      void setType(QString q) {
          m_type = q;
      }
  
  private:
      QString m_type;
      QString m_size;
  //![1]
  };
  
  class AnimalModel : public QAbstractListModel
  {
      Q_OBJECT
  public:
  
      Q_INVOKABLE void test() ;
      void setName(const QString &amp;name);
      enum AnimalRoles {
          TypeRole = Qt::UserRole + 1,
          SizeRole
      };
  
      AnimalModel(QObject *parent = 0);
  //![1]
  //!
  //!
      void setContext(QQmlContext *ctx) {
          m_ctx = ctx;
      }
  
      void addAnimal(const Animal &amp;animal);
  
      int rowCount(const QModelIndex &amp; parent = QModelIndex()) const;
  
      QVariant data(const QModelIndex &amp; index, int role = Qt::DisplayRole) const;
      QHash&lt;int, QByteArray&gt; roleNames() const;
  
  protected:
  
  private:
      QList&lt;Animal&gt; m_animals;
      QQmlContext*  m_ctx;
  
  signals:
      void dataChanged(const QModelIndex &amp; topLeft, const QModelIndex &amp; bottomRight);
  //![2]
  };
  //![2]
  </code></pre>
  
  <p><em>model.h</em></p>
  
  <pre><code>#include "model.h"
  #include "qDebug"
  Animal::Animal(const QString &amp;type, const QString &amp;size)
      : m_type(type), m_size(size)
  {
  }
  
  QString Animal::type() const
  {
      return m_type;
  }
  
  QString Animal::size() const
  {
      return m_size;
  }
  
  
  
  
  AnimalModel::AnimalModel(QObject *parent)
      : QAbstractListModel(parent)
  {
  }
  
  void AnimalModel::addAnimal(const Animal &amp;animal)
  {
      beginInsertRows(QModelIndex(), rowCount(), rowCount());
      m_animals &lt;&lt; animal;
      endInsertRows();
  }
  
  void AnimalModel::test() {
  
    m_animals[0].setType("Lion");
    emit dataChanged(QModelIndex(),QModelIndex());
  
    //I also tried:
    QModelIndex topLeft = createIndex(0,0);
    emit dataChanged(topLeft, topLeft);
  
  
   }
  
  int AnimalModel::rowCount(const QModelIndex &amp; parent) const {
      Q_UNUSED(parent);
      return m_animals.count();
  }
  
  QVariant AnimalModel::data(const QModelIndex &amp; index, int role) const {
      if (index.row() &lt; 0 || index.row() &gt;= m_animals.count())
          return QVariant();
  
      const Animal &amp;animal = m_animals[index.row()];
      if (role == TypeRole)
          return animal.type();
      else if (role == SizeRole)
          return animal.size();
      return QVariant();
  }
  
  //![0]
  QHash&lt;int, QByteArray&gt; AnimalModel::roleNames() const {
      QHash&lt;int, QByteArray&gt; roles;
      roles[TypeRole] = "type";
      roles[SizeRole] = "size";
      return roles;
  }
  //![0]
  </code></pre>
  
  <p><em>model.cpp</em></p>
  
  <pre><code>#include "model.h"
  
  #include &lt;QGuiApplication&gt;
  #include &lt;qqmlengine.h&gt;
  #include &lt;qqmlcontext.h&gt;
  #include &lt;qqml.h&gt;
  #include &lt;QtQuick/qquickitem.h&gt;
  #include &lt;QtQuick/qquickview.h&gt;
  
  //![0]
  int main(int argc, char ** argv)
  {
      QGuiApplication app(argc, argv);
  
      AnimalModel model;
      model.addAnimal(Animal("Wolf", "Medium"));
      model.addAnimal(Animal("Polar bear", "Large"));
      model.addAnimal(Animal("Quoll", "Small"));
  
      QQuickView view;
      view.setResizeMode(QQuickView::SizeRootObjectToView);
      QQmlContext *ctxt = view.rootContext();
      ctxt-&gt;setContextProperty("myModel", &amp;model);
  //![0]
  
      view.setSource(QUrl("qrc:view.qml"));
  
  
      view.show();
  
      return app.exec();
  }
  </code></pre>
  
  <p><em>main.cpp</em></p>
  
  <pre><code>import QtQuick 2.0
  import QtQuick 2.4
  import QtQuick.Controls 1.3
  import QtQuick.Window 2.2
  import QtQuick.Dialogs 1.2
  import QtQuick.Layouts 1.2
  import QtQml.Models 2.1
  import QtQuick.Controls.Styles 1.2
  
  
  //![0]
  ListView {
      width: 200; height: 250
  
      model: myModel
      delegate: Text { text: "Animal: " + type + ", " + size }
  
      MouseArea {
          anchors.fill: parent
          cursorShape: Qt.PointingHandCursor
          onClicked: {
  
          }
      }
      Button {
          anchors.bottom: parent.bottom
          width:50; height:50
          text:"click"
          onClicked: {
              myModel.test()
          }
  
      }
  
  }
  //![0]
  </code></pre>
  
  <p><em>View.qml</em>    </p>
  
  <p>Do you have any idea why it doesn't work ?
  Thanks a lot !</p>