Important: Please read the Qt Code of Conduct -

[SOLVED]Possible to transfer QML grabToImage result to C++?

  • Is there any way to transfer the image resulting from a grabToImage in QML to C++ please, rather than the saveToFile shown in the documentation?

    itemId.grabToImage(function(result) {

    Below is the closest thing I've found to a solution, but I was wondering if there is a more mainstream/supported method?

    Thank you.

  • Kept searching and found a solution to my own question:
    in MyClass.cpp:

    void MyClass::getGrabbedImage(QObject* i)
        QQuickItemGrabResult *item = nullptr;
        item = qobject_cast<QQuickItemGrabResult*>(i);
        QImage qi(item->image());

    Q_INVOKABLE void getGrabbedImage(QObject*);

    ..and in the .qml:

    itemId.grabToImage(function(result) {myClass.getGrabbedImage(result);});

Log in to reply