How do I delete a file in QML + JS?
A snippet of my javascript code, that makes a screenshot and saves it:
function commitSave(slot) {
if ((slot === null ) || (slot < 0 )) {
_saving = false
return false
}
gameRoot.grabToImage(function(result) {
if (result) {
var filename = "save_" + slot + ".jpg"
var dir = StandardPaths.data
result.saveToFile(dir + "/" + filename)
Components.SaveManager.commitSave(filename)
}
_saving = false
}, Qt.size(thumbWidth, thumbHeight))
}
There seems to be no way to delete these screenshots. When I delete a slot, the image file is orphaned.
To me, it seems strange to be able to be able to write a file in javascript, but not to be able to delete the file.
function deleteSave(slot) {
if (!_db) initialize()
_db.transaction(function(tx) {
tx.executeSql("DELETE FROM saves WHERE slot = ?", [slot])
})
//var filename = StandardPaths.data + "/save_" + slot + ".jpg"
//if (Qt.fileExists(filename)) Qt.removeFile(filename)
// Yeah, it seems to be impossible to delete files
// So we can create screenshots, but when we delete a save
// the images are orphaned.
// This sucks
return
}
If I am missing something, please let me know.