Printscreen QML item C++

  • Is it possible to grab printscreen of QML item without saving it to file? I don't want to save image to file with myQmlItem.grabToImage(function(result) { result.saveToFile("myImage.png"); }); because I will use the image in underlying C++ code. Of course, I can save image to file, then read it back in C++ but it would be good if I can access the image in C++ directly without storing it and reading back.

  • Moderators



    myItem.grabToImage( function(result) {
            } );


    void processQMLImage(QObject* imageObj)
        if( QQuickItemGrabResult* item = qobject_cast<QQuickItemGrabResult*>(imageObj) )
              QImage image = item->image();

  • Moderators

    @MartinD Or you can just do it directly by calling follwing function from QML:

    void capture(QQuickItem *item)
        auto grabResult = item->grabToImage(QSize(50,50));
        connect(, &QQuickItemGrabResult::ready, [=]() {
            QImage image =>image();

  • Thanks, very useful!

  • I want grab QML item to save video. eg: mp4
    Is there a way to record the layer ?

Log in to reply