Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. File saving problem
Qt 6.12 LTS is out! See what's new in the release blog

File saving problem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 758 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • FortigaF Offline
    FortigaF Offline
    Fortiga
    wrote on last edited by
    #1

    Hi everyone

    I was trying to improve the Project qt
    alt text

    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 time

    function 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 filename

    The 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

    Juste pour aller de l'avant et apprendre des choses, lorsque vous voulez devenir une légende, cela ne se fait pas du jour au lendemain.

    1 Reply Last reply
    0
    • FortigaF Fortiga

      help svp

      johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #3

      @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
                  }
      
              }
          }
      
      FortigaF 1 Reply Last reply
      0
      • FortigaF Offline
        FortigaF Offline
        Fortiga
        wrote on last edited by
        #2

        help svp

        Juste pour aller de l'avant et apprendre des choses, lorsque vous voulez devenir une légende, cela ne se fait pas du jour au lendemain.

        johngodJ 1 Reply Last reply
        0
        • FortigaF Fortiga

          help svp

          johngodJ Offline
          johngodJ Offline
          johngod
          wrote on last edited by
          #3

          @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
                      }
          
                  }
              }
          
          FortigaF 1 Reply Last reply
          0
          • johngodJ johngod

            @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
                        }
            
                    }
                }
            
            FortigaF Offline
            FortigaF Offline
            Fortiga
            wrote on last edited by
            #4

            @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

            Juste pour aller de l'avant et apprendre des choses, lorsque vous voulez devenir une légende, cela ne se fait pas du jour au lendemain.

            1 Reply Last reply
            0
            • FortigaF Fortiga has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved