Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using text file in resources for read and write in to text file.

Using text file in resources for read and write in to text file.

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 1.9k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Write it to a real file. See also QStandardPaths.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    T 1 Reply Last reply
    2
    • Christian EhrlicherC Christian Ehrlicher

      Write it to a real file. See also QStandardPaths.

      T Offline
      T Offline
      TheCeylann
      wrote on last edited by
      #5

      @Christian-Ehrlicher I can print to file. What I need is for the application to find the file path when I run it on another computer. How can I do that?

      Christian EhrlicherC 1 Reply Last reply
      0
      • T TheCeylann

        @Christian-Ehrlicher I can print to file. What I need is for the application to find the file path when I run it on another computer. How can I do that?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @TheCeylann said in Using text file in resources for read and write in to text file.:

        How can I do that?

        Someone has to copy the file from computer A to computer B. Or store the file somewhere in the internet where you can access it from every computer with internet connection. Don't know your usecase though.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        T 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @TheCeylann said in Using text file in resources for read and write in to text file.:

          How can I do that?

          Someone has to copy the file from computer A to computer B. Or store the file somewhere in the internet where you can access it from every computer with internet connection. Don't know your usecase though.

          T Offline
          T Offline
          TheCeylann
          wrote on last edited by
          #7

          @Christian-Ehrlicher I will store the password inside the text file. Uploading it somewhere can be a problem. Is there a way to define the file inside the file folder instead of defining it as full path. We can call files that are in the same folder like HTML only by their names. Is there a way to do this in Qt c++?

          B JonBJ 2 Replies Last reply
          0
          • T TheCeylann

            @Christian-Ehrlicher I will store the password inside the text file. Uploading it somewhere can be a problem. Is there a way to define the file inside the file folder instead of defining it as full path. We can call files that are in the same folder like HTML only by their names. Is there a way to do this in Qt c++?

            B Offline
            B Offline
            Bonnie
            wrote on last edited by
            #8

            @TheCeylann You can use QCoreApplication::applicationDirPath(), like

            QCoreApplication::applicationDirPath() + "/test.txt"
            
            Christian EhrlicherC 1 Reply Last reply
            0
            • B Bonnie

              @TheCeylann You can use QCoreApplication::applicationDirPath(), like

              QCoreApplication::applicationDirPath() + "/test.txt"
              
              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @Bonnie This is the completely wrong directory - see my answer above: https://forum.qt.io/topic/134385/using-text-file-in-resources-for-read-and-write-in-to-text-file/6

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              B 1 Reply Last reply
              0
              • T TheCeylann

                @Christian-Ehrlicher I will store the password inside the text file. Uploading it somewhere can be a problem. Is there a way to define the file inside the file folder instead of defining it as full path. We can call files that are in the same folder like HTML only by their names. Is there a way to do this in Qt c++?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #10

                @TheCeylann
                I don't know what your last post means. But yes you can specify a plain filename without a path to QFile(). The problem is where do you think that is sought relative to? It will be the current working directory your application has when it's running. And you essentially have no control over that, and don't know what it might be. It will not necessarily have any relation at all to where your executable is installed or where your other files involved in the build/installation might be.

                That is why you should use something based off QStandardPaths, so you know where it actually is.

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @Bonnie This is the completely wrong directory - see my answer above: https://forum.qt.io/topic/134385/using-text-file-in-resources-for-read-and-write-in-to-text-file/6

                  B Offline
                  B Offline
                  Bonnie
                  wrote on last edited by
                  #11

                  @Christian-Ehrlicher
                  The OP ask for a HTML-like way, so I feel he just want to store the file with the exe.
                  I'm sure he should also learn to use QStandardPaths. :)

                  JonBJ 1 Reply Last reply
                  1
                  • B Bonnie

                    @Christian-Ehrlicher
                    The OP ask for a HTML-like way, so I feel he just want to store the file with the exe.
                    I'm sure he should also learn to use QStandardPaths. :)

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #12

                    @Bonnie
                    But OP is asking to be able to write to file too, right? "HTML-like way" is not for writing to files, is it?

                    B 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Bonnie
                      But OP is asking to be able to write to file too, right? "HTML-like way" is not for writing to files, is it?

                      B Offline
                      B Offline
                      Bonnie
                      wrote on last edited by
                      #13

                      @JonB Right, but there're still quite many portable applications choose to store their configuration file, which could be both read and written, with the exe file.
                      QStandardPaths is not very friendly to portable applications though.

                      JonBJ 1 Reply Last reply
                      0
                      • B Bonnie

                        @JonB Right, but there're still quite many portable applications choose to store their configuration file, which could be both read and written, with the exe file.
                        QStandardPaths is not very friendly to portable applications though.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #14

                        @Bonnie said in Using text file in resources for read and write in to text file.:

                        which could be both read and written, with the exe file.

                        Really? Under Linux??

                        And nowadays under Windows apps are installed into Program Files and Win 10+ doesn't allow users to write there any more, does it?

                        B 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @Bonnie said in Using text file in resources for read and write in to text file.:

                          which could be both read and written, with the exe file.

                          Really? Under Linux??

                          And nowadays under Windows apps are installed into Program Files and Win 10+ doesn't allow users to write there any more, does it?

                          B Offline
                          B Offline
                          Bonnie
                          wrote on last edited by Bonnie
                          #15

                          @JonB No, of course Windows!
                          Portable applications are those without installers, they wouldn't be installed into Program Files :)

                          JonBJ 1 Reply Last reply
                          0
                          • B Bonnie

                            @JonB No, of course Windows!
                            Portable applications are those without installers, they wouldn't be installed into Program Files :)

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #16

                            @Bonnie
                            I didn't know it was Windows-only, thought it might be X-platform. But I had added to my post that nowadays you cannot write into Windows Program Files, can you?
                            Oh OK, you & I are cross-posting now.
                            Sometimes I run "portable apps" off a read-only USB stick....

                            QStandardPaths is not very friendly to portable applications though.

                            What about e.g. QStandardPaths::AppDataLocation or other App... ones?

                            B 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @Bonnie
                              I didn't know it was Windows-only, thought it might be X-platform. But I had added to my post that nowadays you cannot write into Windows Program Files, can you?
                              Oh OK, you & I are cross-posting now.
                              Sometimes I run "portable apps" off a read-only USB stick....

                              QStandardPaths is not very friendly to portable applications though.

                              What about e.g. QStandardPaths::AppDataLocation or other App... ones?

                              B Offline
                              B Offline
                              Bonnie
                              wrote on last edited by Bonnie
                              #17

                              @JonB No, a typical usage of a portable application is coping its folder to an USB disk and you can put it on different computers and run it with remembering the configurations you already made.
                              How could the App... ones do that?
                              Sure there will be unwritable risks, but if the portablity is more important, then I have to accept that.

                              JonBJ 1 Reply Last reply
                              0
                              • B Bonnie

                                @JonB No, a typical usage of a portable application is coping its folder to an USB disk and you can put it on different computers and run it with remembering the configurations you already made.
                                How could the App... ones do that?
                                Sure there will be unwritable risks, but if the portablity is more important, then I have to accept that.

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #18

                                @Bonnie said in Using text file in resources for read and write in to text file.:

                                How could the App... ones do that?

                                Perhaps you had understood that the OP wishes to write to a file and then take that updated file to another computer, but I had not. Clearly that changes the equation! :)

                                1 Reply Last reply
                                0

                                • Login

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