I want to grab screen of my QML application. But my root QML object is ApplicationWindow, so I can\'t use QQuickView to show it. Instead I have to use
ApplicationWindow
QQuickView
You can cast ApplicationWindow(QML) to QQuickWindow(C++). Then, It will be easy to take screenshot.
void ScreenShot(QQuickWindow *widget) { QPixmap pixmap = QPixmap::fromImage(widget->grabWindow()); QFile f("your_name.png"); f.open(QIODevice::WriteOnly); if(f.isOpen()) { pixmap.save(&f, "PNG"); }