title: What is the right way to use QQuickImageProvider?
body: <p>I need to select dynamically qpixmaps to display inside QML Image items. That qpixmaps should be cropped from the source qpixmap, which I'm going to set from the QML file. I'd like them to be cropped by C++ code on the first demand from QML and to be cached for the future use. For dynamical images manipulating it's ought to derive my own class from QQuickImageProvider and load it to QML Application engine. But how can I control the source qpixmap then? Via property? If yes, then my custom provider must be derived from QObject and it's instance should be declared inside QML, isn't it? But how can it be loaded by the engine then? I feel that this way of implementing is wrong, but which one would be correct?</p>
  
  <p>UPD: Ok, I have a class:</p>
  
  <pre><code>class MyQuickImageProvider : public QQuickImageProvider {
  public:
      ...
      // This method should set the source image path
      void setPath ( QUrl path );
      // Overriden method of base class; should return cropped image
      virtual QPixmap requestPixmap ( const QString &amp;id, QSize *size, const QSize &amp;requestedSize );
      ...
  }
  </code></pre>
  
  <p>In main.cpp it's loaded as:</p>
  
  <pre><code>QQmlApplicationEngine engine;
  ...
  engine.addImageProvider("my_quick_image_provider", new MyQuickImageProvider(QQmlImageProviderBase::Image));
  </code></pre>
  
  <p>I'd like to change source image path via QML. How can I make setPath method accessible to it? The obvious way is to declare the method as Q_INVOKABLE (and derive MyQuickImageProvider from QObject and qmlRegisterType it), but then I should declare the instance of my class within the QML source:</p>
  
  <pre><code>MyQuickImageProvider {
      id: my_quick_image_provider
      ...
  }
  </code></pre>
  
  <p>The access to it from main.cpp will be problematic. And such a design seems weird to me. Is there any more elegant solution?</p>