File saving problem
-
Hi everyone
I was trying to improve the Project qt

The problem is that at the time of saving the file
the file path is lost once saved you can't do it a second timefunction savefunc() { if(document.fileName === ("untitled.txt")) { saveDialog.open() } else { console.log(document.fileName) document.save(document.fileName) } }I check that filename is untitled.txt which is by default write
so if it's yes save dialog.open()
otherwise I use the path stored in filenameThe project is the same as that of
https://code.qt.io/cgit/qt/qtdeclarative.git/tree/examples/quickcontrols/texteditor?h=6.5
except that it does not present a recorded function but saves as -
@Fortiga Hi
You have to save the location of the saved file so you can use it at the next time. I changed the saveDialog in textEditor.qml, something like this works:property url savedLocation: "" FileDialog { id: saveDialog fileMode: FileDialog.SaveFile defaultSuffix: document.fileType nameFilters: openDialog.nameFilters selectedNameFilter.index: document.fileType === "txt" ? 0 : 1 currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation) onAccepted: { console.log("currentFolder:"+currentFolder) savedLocation = currentFolder document.saveAs(selectedFile) } onVisibleChanged: { if (visible && savedLocation !== "") { currentFolder = savedLocation } } } -
@Fortiga Hi
You have to save the location of the saved file so you can use it at the next time. I changed the saveDialog in textEditor.qml, something like this works:property url savedLocation: "" FileDialog { id: saveDialog fileMode: FileDialog.SaveFile defaultSuffix: document.fileType nameFilters: openDialog.nameFilters selectedNameFilter.index: document.fileType === "txt" ? 0 : 1 currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation) onAccepted: { console.log("currentFolder:"+currentFolder) savedLocation = currentFolder document.saveAs(selectedFile) } onVisibleChanged: { if (visible && savedLocation !== "") { currentFolder = savedLocation } } } -
@Fortiga Hi
You have to save the location of the saved file so you can use it at the next time. I changed the saveDialog in textEditor.qml, something like this works:property url savedLocation: "" FileDialog { id: saveDialog fileMode: FileDialog.SaveFile defaultSuffix: document.fileType nameFilters: openDialog.nameFilters selectedNameFilter.index: document.fileType === "txt" ? 0 : 1 currentFolder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation) onAccepted: { console.log("currentFolder:"+currentFolder) savedLocation = currentFolder document.saveAs(selectedFile) } onVisibleChanged: { if (visible && savedLocation !== "") { currentFolder = savedLocation } } }@johngod Thank you for your reply
in fact it was necessary to replace document.save(fileName) by document.save(FileUrl)function savefunc() { if(document.fileName === ("untitled.txt")) { saveDialog.open() } else { document.save(document.fileUrl) } }Thank you
-
F Fortiga has marked this topic as solved on