O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing save composition to an image

Saving a composition to an image is straightforward. If we look at the QQuickItem's API (http://doc.qt.io/qt-5.9/qquickitem.html), from which both Item and Scene3D derive, we can notice how it exposes a grabToImage method. In turn, this method returns a pointer to a QQuickItemGrabResult object (http://doc.qt.io/qt-5.9/qquickitemgrabresult.html) which exposes a saveToFile method. Since grabToImage works asynchronously, the grab result should be accessed in a callback function, which can be passed as an argument to grabToImage, as in the following example:

item.grabToImage(function(image) {    image.saveTofile();});

To save the image, we will thus just have to call grabToImage for the Scene3D, ask the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required