title: expose a C++ object to QML and listen to change events
body: <p>I have an object that I define in C++ and am trying expose a member string to QML. The class is defined as:</p>
  
  <pre><code>#ifndef MYTYPE_H
  #define MYTYPE_H
  #include &lt;QString&gt;
  #include &lt;QObject&gt;
  
  
  class MyType : public QObject
  {
      Q_OBJECT
      Q_PROPERTY(QString foo READ foo WRITE setFoo NOTIFY fooChanged)
  
  public:
      MyType(QObject *parent = nullptr) :
          QObject(parent),
          mFoo("0")
      {
      }
  
      QString foo() const
      {
          return mFoo;
      }
  
      void setFoo(QString foo)
      {
          if (foo == mFoo)
              return;
  
          mFoo = foo;
          emit fooChanged(mFoo);
      }
  
  signals:
      void fooChanged(QString foo);
  
  private:
      QString mFoo;
  };
  
  #endif // MYTYPE_H
  </code></pre>
  
  <p>So I am trying to expose the <code>mFoo</code> object to QML. Now, I am setting it with the application context as:</p>
  
  <pre><code>QtQuickControlsApplication app(argc, argv);
  QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
  
  qmlRegisterType&lt;MyType&gt;("MyType", 1, 0, "MyType");
  MyType myType;
  QObject *topLevel = engine.rootObjects().value(0);
  
  engine.rootContext()-&gt;setContextProperty("foo", &amp;myType);
  </code></pre>
  
  <p>Now in my qml, how can I listen to the change of the string that I am exposing. So I would like a listener method that gets called every time the <code>mFoo</code> member is changing. </p>