How to take Screenshot of QML application without QQuickView

前端 未结 3 857
深忆病人
深忆病人 2021-02-15 11:55

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

3条回答
  •  佛祖请我去吃肉
    2021-02-15 12:55

    You can use rootObjects() and cast its result to QQuickWindow:

    foreach(QObject* obj, engine.rootObjects()) {
      QQuickWindow* window = qobject_cast(obj);
      if (window) {
        QImage image = window->grabWindow();
        qDebug() << image;
      }
    }
    

提交回复
热议问题