title: 'QML Connections: Cannot assign to non-existent Property' despite the opposite being true
body: <p>So, I checked the following questions, which seemed most similar to my existing problem:</p>
  
  <p><a href="https://stackoverflow.com/questions/24406333/qml-using-cpp-signal-in-qml-always-results-in-cannot-assign-to-non-existent-pr">QML: Using cpp signal in QML always results in &quot;Cannot assign to non-existent property&quot;</a></p>
  
  <p>Unfortunately that did not help. (Nor did any other solution that I could find on stackoverflow/google/qt forums, etc)</p>
  
  <p>I kept getting the following two errors:</p>
  
  <blockquote>
    <p>qrc:/view.qml:30:9: QML Connections: Cannot assign to non-existent
    property "onNewFrameReceived" qrc:/view.qml:31: ReferenceError:
    imageProvide is not defined</p>
  </blockquote>
  
  <p>Here is my code (edited down to make it, into a 'Minimum Working Example').</p>
  
  <p>The only files important should be:</p>
  
  <ol>
  <li>main.cpp</li>
  <li>view.qml</li>
  <li>imageprovidervm.cpp</li>
  <li>imageprovidervm.h</li>
  </ol>
  
  <p>I included the <strong>imagesource</strong> class, just to be complete, in case someone wants to compile this on his own as well. </p>
  
  <p><strong>Q1.</strong> So, I don't understand why even after setting the context property in <em>main.cpp</em>, the following error appears.</p>
  
  <blockquote>
    <p>qrc:/view.qml:31: ReferenceError: imageProvide is not defined</p>
  </blockquote>
  
  <p>What is funny is that, intellisense/autocomplete seems to detect imageProvide completely correctly.</p>
  
  <p><strong>Q2.</strong> Even though in my <em>imageprovider.h</em>, I added properties (newimage) and signals (newFrameReceived) that should be seen in the qml file, still I get the following error. Also, the Qt intellisense/autocomplete fails to show my defined signal (onNewFrameReceived) here.</p>
  
  <blockquote>
    <p>qrc:/view.qml:30:9: QML Connections: Cannot assign to non-existent
    property "onNewFrameReceived"</p>
  </blockquote>
  
  <ul>
  <li><strong>Additional info:</strong> Debugging and stopping on a break point in the qml file at line 31, shows in the "locals and expressions" of the qtcreator that I have only 2 signals available here, namely "<em>objectNameChanged</em>" and "<em>targetChanged</em>".
  Why ???</li>
  </ul>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;QGuiApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  #include &lt;QQmlContext&gt;
  
  #include "imageprovidervm.h"
  #include "imagesource.h"
  
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
  
          QQmlApplicationEngine engine;
          QQmlContext *context = new QQmlContext(engine.rootContext());
  
          auto model = std::make_shared&lt;ImageSource&gt;();
  
          auto vm = new ImageProviderVM(model);
          engine.addImageProvider(QLatin1String("imageProvider"), vm);
          context-&gt;setContextProperty("imageProvide", vm );
  
          model-&gt;generateImages();
  
          engine.load(QUrl(QStringLiteral("qrc:/view.qml")));
  
          return app.exec();
      }
  </code></pre>
  
  <p><strong>view.qml</strong></p>
  
  <pre><code>import QtQuick 2.5
  import QtQuick.Controls 1.4
  
  import QtQml.Models 2.2
  import QtQuick.Dialogs 1.2
  import QtQuick.Window 2.0
  
  ApplicationWindow {
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
  
      menuBar: MenuBar {
          Menu {
              title: qsTr("File")
              MenuItem {
                  text: qsTr("&amp;Open")
                  onTriggered: console.log("Open action triggered");
              }
              MenuItem {
                  text: qsTr("Exit")
                  onTriggered: Qt.quit();
              }
          }
      }
  
      Rectangle {
          Connections {
              target: imageProvide
              onNewFrameReceived: image.reload();
          }
          anchors.fill: parent
          Column {
              Image {
                  id: image
                  source: "image://imageProvider/images.jpeg?id=" + Math.random()
                  cache: false
                  asynchronous: true
                  function reload() {
                          var oldSource = source;
                          source = "";
                          source = oldSource;
                      }
              }
          }
      }
      Label {
          text: qsTr("Hello World")
          anchors.centerIn: parent
      }
  }
  </code></pre>
  
  <p><strong>imageprovidervm.h</strong></p>
  
  <pre><code>#ifndef IMAGEPROVIDERVM_H
  #define IMAGEPROVIDERVM_H
  
  #include &lt;QQuickImageProvider&gt;
  #include &lt;QObject&gt;
  #include "imagesource.h"
  
  class ImageProviderVM : public QObject, public QQuickImageProvider
  {
      Q_OBJECT
  public:
      ImageProviderVM(std::shared_ptr&lt;ImageSource&gt; model);
      ~ImageProviderVM();
  
      virtual QPixmap requestPixmap(const QString &amp;id, QSize *size, const QSize &amp;requestedSize) override;
      virtual QImage requestImage(const QString &amp; id, QSize * size, const QSize &amp; requestedSize) override;
  
      // Properties
      Q_PROPERTY(QImage newimage READ getNewImage NOTIFY newFrameReceived)
  
      // Signals
  signals:
      void newFrameReceived();
  
  private:
      QImage getNewImage() const;
  
      QPixmap m_pixmap;
      QImage m_image;
  
      std::shared_ptr&lt;ImageSource&gt; m_model;
  };
  
  #endif // IMAGEPROVIDERVM_H
  </code></pre>
  
  <p><strong>imageprovidervm.cpp</strong></p>
  
  <pre><code>#include "imageprovidervm.h"
  #include &lt;functional&gt;
  
  #include &lt;QPixmap&gt;
  #include &lt;QDebug&gt;
  
  ImageProviderVM::ImageProviderVM()
      : QQuickImageProvider(QQuickImageProvider::Image)
  {
  }
  
  ImageProviderVM::ImageProviderVM(std::shared_ptr&lt;ImageSource&gt; model)
      : QQuickImageProvider (QQuickImageProvider::Image)
      , m_pixmap()
      , m_model(model)
  {
      m_model-&gt;subscribeNewPixMap([this](QPixmap pixmap) {
          qDebug() &lt;&lt; "setting m_pixmap";
          if (pixmap.size().isValid()) {
              m_pixmap = pixmap;
          }
          else
              qDebug() &lt;&lt; "is it NULL ??? " &lt;&lt; pixmap.isNull();
      });
  
      m_model-&gt;subscribeNewImage([this](QImage image) {
          qDebug() &lt;&lt; "setting m_image";
          if (image.size().isValid()) {
              m_image = image;
              emit newFrameReceived();
          }
          else
              qDebug() &lt;&lt; "is it NULL ??? " &lt;&lt; image.isNull();
      });
  
      qDebug() &lt;&lt; "imageproviderVM constructed";
  }
  
  ImageProviderVM::~ImageProviderVM()
  {
  }
  
  QPixmap ImageProviderVM::requestPixmap(const QString &amp;id, QSize *size, const QSize &amp;requestedSize)
  {
      // look into the parameters id, size and requestedSize once the rest of the structure is there
      return m_pixmap;
  }
  
  QImage ImageProviderVM::requestImage(const QString &amp; id, QSize * size, const QSize &amp; requestedSize)
  {
      return m_image;
  }
  
  QQuickTextureFactory * ImageProviderVM::requestTexture(const QString &amp; id, QSize * size, const QSize &amp; requestedSize)
  {
  //    return QQuickTextureFactory::createTexture();
  }
  
  QImage ImageProviderVM::getNewImage() const
  {
      return m_image;
  }
  </code></pre>
  
  <p><strong>imagesource.h</strong></p>
  
  <pre><code>#ifndef IMAGESOURCE_H
  #define IMAGESOURCE_H
  
  #include &lt;QImage&gt;
  #include &lt;boost/signals2.hpp&gt;
  
  class ImageSource
  {
  public:
      ImageSource();
      void generateImages();
      void generatePixmaps(const QString &amp;id, QSize *size, const QSize &amp;requestedSize);
  
      typedef boost::signals2::signal&lt;void (QPixmap)&gt; NewPixMapDelegate;
      boost::signals2::connection subscribeNewPixMap(NewPixMapDelegate::slot_function_type f);
  
      typedef boost::signals2::signal&lt;void (QImage)&gt; NewImageDelegate;
      boost::signals2::connection subscribeNewImage(NewImageDelegate::slot_function_type f);
  
  
  private:
      NewPixMapDelegate m_newPixMap;
      NewImageDelegate m_newImage;
  };
  
  #endif // IMAGESOURCE_H
  </code></pre>
  
  <p><strong>imagesource.cpp</strong></p>
  
  <pre><code>#include "imagesource.h"
  
  #include &lt;QPixmap&gt;
  #include &lt;QPainter&gt;
  
  #include &lt;thread&gt;
  
  ImageSource::ImageSource()
  {
  }
  
  boost::signals2::connection ImageSource::subscribeNewImage(NewImageDelegate::slot_function_type f)
  {
      return m_newImage.connect(f);
  }
  
  void ImageSource::generateImages()
  {
      std::thread t([this]() {
          auto image = QImage("/home/junaid/testing_ground/fourthtime/images.jpeg");
          m_newImage(image);
  
          /// useless wait. just simulating that another image comes after sometime and so on onwards.
          int random_wait = 2; //sec
          sleep(random_wait);
  
          image = QImage("/home/junaid/Downloads/pnggrad16rgb.png");
          m_newImage(image);
      });
      t.detach();
  }
  
  boost::signals2::connection ImageSource::subscribeNewPixMap(NewPixMapDelegate::slot_function_type f)
  {
      return m_newPixMap.connect(f);
  }
  
  void ImageSource::generatePixmaps(const QString &amp;id, QSize *size, const QSize &amp;requestedSize)
  {
      int width = 100;
      int height = 50;
  
      if (size) {
          *size = QSize(width, height);
      }
      QPixmap pixmap(requestedSize.width() &gt; 0 ? requestedSize.width() : width,
                     requestedSize.height() &gt; 0 ? requestedSize.height() : height);
      pixmap.fill(QColor(id).rgba());
  
      // write the color name
      QPainter painter(&amp;pixmap);
      QFont f = painter.font();
      f.setPixelSize(20);
      painter.setFont(f);
      painter.setPen(Qt::black);
      if (requestedSize.isValid())
          painter.scale(requestedSize.width() / width, requestedSize.height() / height);
      painter.drawText(QRectF(0, 0, width, height), Qt::AlignCenter, id);
  
      m_newPixMap(pixmap);
  }
  </code></pre>
  
  <p>and here is the CMake file:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8.12)
  
  project(non_existent_property LANGUAGES CXX)
  
  set(CMAKE_INCLUDE_CURRENT_DIR ON)
  set(CMAKE_AUTOMOC ON)
  set(CMAKE_AUTORCC ON)
  
  find_package(Qt5 COMPONENTS Core Quick REQUIRED)
  
  file( GLOB SRCS *.cpp *.h )
  
  add_executable(${PROJECT_NAME} "qml.qrc" ${SRCS})
  
  target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Quick "pthread")
  </code></pre>