For some reason, saving a png back out from qml directly doesn't work. I have a qml UI on top of a Golang application. When I do
source.grabToImage(function(result){
console.log("image: ", result.url)
if (!result.saveToFile(urlNoProtocol)){
console.error('Unknown error saving to',urlNoProtocol);
} else {
console.log("saved to " + urlNoProtocol)
}
I get an error saving out. The location to save the file is coming from a fileDialog and I preprocess it to remove the file://
which I understand needs to be removed before using saveToFile
. However I get an unknown error saving from the above code.
I suspect this is something to do with the qml being embedded in the binary application (perhaps to do with qrc://
or something)
Anyway my current plan is to send the image to the golang backend and save it out from there, so my question is, how from grabToImage
or saveToFile
can I get the image bytes that I will then save?
N.B Using therecipe/qt for the interface between Golang and qml
I have used this method for grabbing screen shots..
function performScreenShot(item, name) {
if(typeof(item) === "undefined") {
return;
}
else if(typeof(name) !== "string") {
name = "screenshot.png"
}
item.grabToImage(function(result) {
result.saveToFile(name);
});
}
Usage example:-
performScreenShot(main, "screenshot-" + screenShotIndex + ".png")
Where main is my object id and screenShotIndex is something im incrementing so as not to override any previous capture.
Ensure that you have write permission on the device.