title: QML: Type Error with custom QObject
body: <p>I'm trying out something in QML to try and make it alittle easier to merge the two more seamlessly; to be precise, I'm trying to link an object with structured data to QML.</p>
  
  <p>I have the following setup:</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  #include &lt;QtQml&gt;
  #include "dataobject.h"
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
      qmlRegisterType&lt;DataObject&gt;("DO", 1,0,"DataObject");
  
      QQmlApplicationEngine engine;
      engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
  
      return app.exec();
  }
  </code></pre>
  
  <p>dataobject.h:</p>
  
  <pre><code>#ifndef DATAOBJECT_H
  #define DATAOBJECT_H
  
  #include &lt;QObject&gt;
  #include &lt;QVariant&gt;
  #include &lt;iostream&gt;
  
  class DataObject : public QObject
  {
      Q_OBJECT
      Q_PROPERTY(qreal a MEMBER a NOTIFY aChanged)
      Q_PROPERTY(qreal b MEMBER b NOTIFY bChanged)
  public:
      explicit DataObject(QObject *parent = 0);
  
  signals:
      void aChanged();
      void bChanged();
  
  public slots:
      void printState() {
          using namespace std;
          cout &lt;&lt; a &lt;&lt; ", " &lt;&lt; b &lt;&lt; endl;
      }
  
  private:
      qreal a;
      qreal b;
  };
  
  #endif // DATAOBJECT_H
  </code></pre>
  
  <p>dataobject.cpp:</p>
  
  <pre><code>#include "dataobject.h"
  
  DataObject::DataObject(QObject *parent) :
      QObject(parent)
  {
      connect(this, SIGNAL(aChanged()), this, SLOT(printState()));
      connect(this, SIGNAL(bChanged()), this, SLOT(printState()));
  }
  </code></pre>
  
  <p>main.qml:</p>
  
  <pre><code>import DO 1.0
  
  ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
  
      menuBar: MenuBar {
          Menu {
              title: qsTr("File")
              MenuItem {
                  text: qsTr("Exit")
                  onTriggered: Qt.quit();
              }
          }
      }
      Text {
          text: qsTr("Hello World")
  
          MouseArea {
              property DataObject myData;
              anchors.fill: parent
              drag.target: parent
  
              onReleased: {
                  myData.a = mouse.x;
                  myData.b = mouse.y;
              }
          }
      }
  }
  </code></pre>
  
  <p>qml.qrc:</p>
  
  <pre><code>&lt;RCC&gt;
      &lt;qresource prefix="/"&gt;
          &lt;file&gt;main.qml&lt;/file&gt;
      &lt;/qresource&gt;
  &lt;/RCC&gt;
  </code></pre>
  
  <p>Now, what I'd hoped was that values generated by QML could be feed into a object in C++ directly (i.e. the onReleased handler in the MouseArea trying to write to the myData field). However, this basic proof of concept doesn't work, but I don't really understand why.</p>
  
  <p>The error I get (on drag and release of the mouse button) is:
  qrc:///main.qml:29:TypeError:Type error</p>
  
  <p>Which matches up with the line "myData.a = mouse.x;", so it fails straight away.</p>
  
  <p>Any idea's where I'm going wrong? I've tried with the fields being int, double, QVariant, and qreal, none of which have worked. Is in a fundamental inability in QML to link objects like that? If so, any idea how, for example, anchors.fill is implemented in the Qt source code? </p>