title: QQuickWindow::grabWindow: scene graph already in use
body: <p>I tried the code shown here: <a href="https://stackoverflow.com/questions/17090019/how-to-take-screenshot-qt-qml">How to take ScreenShot Qt/QML</a></p>
  
  <p>On execution I am getting the error written in the title.</p>
  
  <p>My <strong><em>main.cpp</em></strong> is:</p>
  
  <pre><code>#include &lt;QGuiApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  #include &lt;QQuickWindow&gt;
  #include &lt;QImage&gt;
  #include &lt;QDebug&gt;
  #include "screenshot.h"
  #include &lt;QQuickView&gt;
  #include &lt;QQmlContext&gt;
  
  int main(int argc, char *argv[])
  {
      QGuiApplication app(argc, argv);
  
      const char* drigUi = "DrigUI"; 
      qmlRegisterType &lt;screenCapture&gt; (drigUi, 1, 0, "ScreenShot");
  
      QQmlApplicationEngine engine;
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  
      return app.exec();
  }
  </code></pre>
  
  <p>I used this <strong>capture</strong> function:</p>
  
  <pre><code>void screenCapture::capture(QString const &amp;path) const
  {
      QImage img = currentView_-&gt;grabWindow();
      img.save(path);
  }
  </code></pre>
  
  <p>and added the following in the constructor:</p>
  
  <pre><code>currentView_ = new QQuickView;
  </code></pre>
  
  <p>My <strong><em>main.qml</em></strong> :</p>
  
  <pre><code>import QtQuick 2.4
  import QtQuick.Window 2.2
  
  import DrigUI 1.0
  
  Window
  {
      visible: true
      height: 370
      width: 370
  
      ScreenShot { id: screenShot }
  
      Rectangle
      {
          id: ll
          height: 30
          width: 50
          x: 180; y: 0; color: "red"
          MouseArea
          {
              anchors.fill: parent
              onClicked: screenShot.capture ("l.png")
          }
      }
  }
  </code></pre>
  
  <p>What does that error mean? What is the way to solve it? What else info can I provide here?</p>