title: Qt/QML : Send QImage From C++ to QML and Display The QImage On GUI
body: <p>I created a class <code>Publisher</code> which periodically emits a <code>QImage</code> object. </p>
  
  <p>However I'm having a tough time drawing the <code>QImage</code> to a QML element. It appears that the <code>Image</code> and <code>Canvas</code> QML components require a <code>QUrl</code> instead of a <code>QImage</code>, but I'm not sure how to convert my <code>QImage</code> to a <code>QUrl</code>. Edit4: When I say QUrl, I don't mean I'm trying to convert an image to a URL. That's nonsense. I mean I want to generate a reference to this image, which is not on disk, and the data type that QML components are asking for is a URL.</p>
  
  <p>I've done some research and found that <code>QQuickImageProvider</code> provides a solution, but I haven't found any documentation explaining how to convert my <code>QImage</code> signal to a <code>QUrl</code> that I can use for drawing. Any example code or reference documentation would be appreciated.</p>
  
  <p>Thanks for your help!</p>
  
  <p>Edit1:</p>
  
  <p>I've taken a look here: <a href="http://qt-project.org/doc/qt-5.0/qtquick/qquickimageprovider.html">http://qt-project.org/doc/qt-5.0/qtquick/qquickimageprovider.html</a> and I do not see how I pass a QImage to the quick image provider and from it create a QUrl.</p>
  
  <p>Edit2. Here is the header. The implementation should not be important.</p>
  
  <pre><code>class Publisher
  {
      Q_OBJECT
  
  public:
      Publisher(QObject* parent = 0);
  
      virtual ~Publisher(void);
  
  Q_SIGNALS:
  
      void newImage(const QImage&amp; newImage);
  };
  </code></pre>
  
  <p>Edit 3. Here is my QML code, but I don't know how to draw my QImage, so this code is kind of meaningless.</p>
  
  <p><strong>my main.cpp file</strong>:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QGuiApplication app(argc, argv);
  
      qmlRegisterType&lt;Publisher&gt;("Components", 1, 0, "Publisher");
  
      QtQuick2ApplicationViewer viewer;
      viewer.setMainQmlFile(QStringLiteral("qml/QQuickViewExample/main.qml"));
      viewer.showExpanded();
  
      return app.exec();
  }
  </code></pre>
  
  <p><strong>my main.qml file</strong>:</p>
  
  <pre><code>import QtQuick 2.0
  import Components 1.0
  
  Rectangle {
      id : testRect
      width: 360
      height: 360
  
      Image{
          anchors.fill: parent
          id: myImage
  
          Publisher {
              id: myPub
  
              onNewImage: {
                  myImage.source = newImage;  #I know this doesnt work, it needs a QUrl and not a QImage
              }
          }
      }
  }
  </code></pre>