title: How to implement WPF-like MVVM in Qt/C++/QML?
body: <p>I'm writing a proof of concept application, that is very simple. Basically it's composed of a UI where a list of "Note" type objects is displayed in a QML ListView.</p>
  
  <p>I then have a few classes which is something along the lines:</p>
  
  <pre><code>#ifndef NOTE_H
  #define NOTE_H
  
  #include &lt;string&gt;
  
  using namespace std;
  class Note
  {
  public:
      Note(QObject* parent = 0)
          : QObject(parent)
      {
  
      }
  
      Note(const int id, const string&amp; text)
          : _id(id), _text(text)
      {
      }
  
      int id()
      {
          return _id;
      }
  
      const string text()
      {
          return _text;
      }
  
      void setText(string newText)
      {
          _text = newText;
      }
  
  private:
      int _id;
      string _text;
  };
  
  #endif // NOTE_H
  </code></pre>
  
  <p>Then a repository:</p>
  
  <pre><code>class NoteRepository : public Repository&lt;Note&gt;
  {
  public:
      NoteRepository();
      ~NoteRepository();
  
      virtual shared_ptr&lt;Note&gt; getOne(const int id);
      virtual const unique_ptr&lt;vector&lt;Note&gt;&gt; getAll();
      virtual void add(shared_ptr&lt;Note&gt; item);
  private:
      map&lt;int, shared_ptr&lt;Note&gt;&gt; _cachedObjects;
  };
  </code></pre>
  
  <p>Finally a ViewModel that exposes Note to QML</p>
  
  <pre><code>class MainViewModel : public QObject
  {
      Q_OBJECT
      Q_PROPERTY(QQmlListProperty&lt;Note&gt; notes READ notes NOTIFY notesChanged)
      Q_PROPERTY(int count READ count() NOTIFY countChanged)
  public:
      MainViewModel(QObject *newParent = 0);
      int count();
      QQmlListProperty&lt;Note&gt; notes();
  signals:
      void notesChanged();
      void countChanged();
  public slots:
  private:
      std::shared_ptr&lt;UnitOfWork&gt; _unitOfWork;
      static void appendNote(QQmlListProperty&lt;Note&gt; *list, Note *note);
      QList&lt;Note*&gt; _notes;
  };
  </code></pre>
  
  <p><strong>PLEASE DON'T MIND ANY C++ MISTAKES HERE and mind they are incomplete, it's not the point at this moment as I'm constantly adapting this as I learn.</strong></p>
  
  <p>The point where I'm struggling is, how to expose a list-like object to QML? The requirement is this list must be dynamic, one should be able to add, delete and modify the text of a note. When the list is modified by C++, it should also notify the UI (signal). </p>
  
  <p>I tried QQmlListProperty, but couldn't figure a way of exposing it to QML. Then I read on another SO post this type can't be modified by QML (??), and I stumbled upon QAbstractItemModel.</p>
  
  <p>Anyhow, can anyone point me to the right direction? </p>