Hi, all!

I have an application - shapes viewer. My app consists of two main components. There are OpenGL Viewer and Qt/Qml toolbar. I am trying to take screenshot of my app.

First time I have tried this one:
Qt Code:
  1. QQuickWindow* window = this->window();
  2. if (window)
  3. {
  4. QImage image = window->grabWindow();
  5. image.save(QString(path)); // The path is valid
  6. }
To copy to clipboard, switch view to plain text mode 

At the first launch of the app the screenshot was taken properly, but app was frozen. On the next launches app was freezing without taking screenshot. The app is freezing when I am calling
Qt Code:
  1. QImage image = window->grabWindow();
To copy to clipboard, switch view to plain text mode 

Also, I have tried, but it is doesn't work:
Qt Code:
  1. QScreen *screen = QGuiApplication::primaryScreen();
  2. if(screen)
  3. {
  4. QPixmap originalPixmap = screen->grabWindow(this->window()->winId());
  5. if(originalPixmap.save(QString(path)))
  6. {
  7. qDebug() << QString("Screenshot saved");
  8. }
  9. else
  10. {
  11. qDebug() << QString("Screenshot not saved");
  12. }
  13. }
To copy to clipboard, switch view to plain text mode 

Please, help to solve this problem