I am working with a Qt QML project. In that I need to take create some images during process. The actual image creation and storage should take places in background.
For this I have a qml template file as shown below
import QtQuick 2.0
Item {
id:area
width:960
height: 960
visible: true
Image {
id: name
source: "file.jpg"
anchors.fill: parent
}
StudentDetails
{
anchors.centerIn: parent
}
}
And I want to render some details from cpp function to this QML file. i.e I want to update some student details from data base and render to this qml and store as image. For that I tried all the below methods.
// Using QQmlComponent
QQmlEngine engine;
QQmlComponent component(&engine,
QUrl::fromLocalFile("MyItem.qml"));
QObject *object = component.create();
object->grabToImage(function(resut){result.saToFile("Stud01.png");}, Qt.size(960, 960));
Actually , this grabToImage call is not working here. This is just a qml template and I am not going to load this qml. just update some stud details and store as image. I also tried to call a function in qml and that qml file inside handling the grab image call.
But in both cases its not working. I am getting error like, Item::GrabToImage will not working since it is not attached to a window.
Can I do it? Can't I save an image from QML template. Is there any other way to save the qml as image.