title: Can't write to a C++ object from QML
body: <p>I have a program that displays images and can put different filters on these images. In the QML GUI I have a series of buttons that let you set which highlights are enabled.</p>
  
  <pre><code>Column{
      id: highlightButtons
      anchors {left: frameViewer.right; top: parent.top; leftMargin: 10; topMargin: 10 }
      spacing: 20
      Rectangle{
          id: class1
          color: "red"
          height: 45
          width: 45
          radius: 12
          MouseArea{
              anchors.fill: parent
              onClicked: {hl.red = frames[frameList.currentIndex];
                          loadImages(); console.log(hl.red)}
          }
      }
  
      Rectangle{
          id: class2
          color: "green"
          height: 45
          width: 45
          radius: 12
          MouseArea{
              anchors.fill: parent
              onClicked: {hl.green = frames[frameList.currentIndex];
                          loadImages(); console.log(hl.green)}
          }
      }
  
      Rectangle{
          id: class3
          color: "blue"
          height: 45
          width: 45
          radius: 12
          MouseArea{
              anchors.fill: parent
              onClicked: {hl.blue = frames[frameList.currentIndex];
                          loadImages(); console.log(hl.blue)}
          }
      }
  }
  </code></pre>
  
  <p>Where <code>frames</code> is a list of strings.</p>
  
  <p><code>hl</code> is a class that I use to store which highlights are enabled.</p>
  
  <pre><code>class HighlightModel : public QObject
  {
      Q_PROPERTY(QString red READ getRed WRITE setRed NOTIFY redChanged)
      Q_PROPERTY(QString blue READ getGreen WRITE setBlue NOTIFY blueChanged)
      Q_PROPERTY(QString green READ getBlue WRITE setGreen NOTIFY greenChanged)
  public:
      void setRed(QString &amp;frame)
      {
          if(redHighlights.find(frame) != redHighlights.end())
          {
              redHighlights[frame] = !redHighlights[frame];
          }
          else
          {
              redHighlights.insert(std::pair&lt;QString, bool&gt;(frame, true));
          }
          emit redChanged();
      }
  
      void setGreen(QString &amp;frame)
      {
          if(greenHighlights.find(frame) != greenHighlights.end())
          {
              greenHighlights[frame] = !greenHighlights[frame];
          }
          else
          {
              greenHighlights.insert(std::pair&lt;QString, bool&gt;(frame, true));
          }
          emit greenChanged();
      }
  
      void setBlue(QString &amp;frame)
      {
          if(blueHighlights.find(frame) != blueHighlights.end())
          {
              blueHighlights[frame] = !blueHighlights[frame];
          }
          else
          {
              blueHighlights.insert(std::pair&lt;QString, bool&gt;(frame, true));
          }
          emit blueChanged();
      }
  
      bool getRed(QString frame)
      {
          return redHighlights[frame];
      }
      bool getGreen(QString frame)
      {
          return greenHighlights[frame];
      }
      bool getBlue(QString frame)
      {
          return blueHighlights[frame];
      }
  
      std::map&lt;QString, bool&gt; redHighlights;
      std::map&lt;QString, bool&gt; greenHighlights;
      std::map&lt;QString, bool&gt; blueHighlights;
  signals:
      void redChanged();
      void greenChanged();
      void blueChanged();
  
  private:
  
  
  };
  </code></pre>
  
  <p>My understand of <code>Q_PROPERTY</code> is that setting <code>WRITE</code> to <code>setRed</code>, <code>setBlue</code> etc. should mean that when I set <code>hl.red</code> to something, it should call the function I associate with <code>WRITE</code>. However, I have put breakpoints in the code there and that code is never run. When I use <code>console.log</code> to print <code>hl.blue</code> it just prints the string that I tried to pass before. Can anyone clear this up for me? Have I misinterpreted how this works?</p>
  
  <h2>EDIT</h2>
  
  <p>Here is the code where I associate the <code>HighlightModel</code> with the <code>engine</code>:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
      qDebug() &lt;&lt; VERSION_INFO;
      FrameViewerWindow engine;
      InfoHolder ver;
      HighlightModel highlights;
      engine.rootContext()-&gt;setContextProperty("ver", &amp;ver);
      engine.rootContext()-&gt;setContextProperty("hl", &amp;highlights);
      engine.addImageProvider("images", new ImageLoader(QQuickImageProvider::Image, &amp;highlights));
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      return app.exec();
  }
  </code></pre>