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.
Forum Updated to NodeBB v4.3 + New Features

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 2.0k 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.
  • B Bonnie
    17 Feb 2022, 08:39

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

    QCoreApplication::applicationDirPath() + "/test.txt"
    
    C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 17 Feb 2022, 08:40 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 17 Feb 2022, 08:53
    0
    • T TheCeylann
      17 Feb 2022, 07:53

      @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++?

      J Offline
      J Offline
      JonB
      wrote on 17 Feb 2022, 08:42 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
      • C Christian Ehrlicher
        17 Feb 2022, 08:40

        @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 17 Feb 2022, 08:53 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. :)

        J 1 Reply Last reply 17 Feb 2022, 08:55
        1
        • B Bonnie
          17 Feb 2022, 08:53

          @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. :)

          J Offline
          J Offline
          JonB
          wrote on 17 Feb 2022, 08:55 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 17 Feb 2022, 09:06
          0
          • J JonB
            17 Feb 2022, 08:55

            @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 17 Feb 2022, 09:06 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.

            J 1 Reply Last reply 17 Feb 2022, 09:07
            0
            • B Bonnie
              17 Feb 2022, 09:06

              @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.

              J Offline
              J Offline
              JonB
              wrote on 17 Feb 2022, 09:07 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 17 Feb 2022, 09:08
              0
              • J JonB
                17 Feb 2022, 09:07

                @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 17 Feb 2022, 09:08 last edited by Bonnie
                #15

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

                J 1 Reply Last reply 17 Feb 2022, 09:09
                0
                • B Bonnie
                  17 Feb 2022, 09:08

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

                  J Offline
                  J Offline
                  JonB
                  wrote on 17 Feb 2022, 09:09 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 17 Feb 2022, 09:20
                  0
                  • J JonB
                    17 Feb 2022, 09:09

                    @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 17 Feb 2022, 09:20 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.

                    J 1 Reply Last reply 17 Feb 2022, 09:30
                    0
                    • B Bonnie
                      17 Feb 2022, 09:20

                      @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.

                      J Offline
                      J Offline
                      JonB
                      wrote on 17 Feb 2022, 09:30 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

                      18/18

                      17 Feb 2022, 09:30

                      • Login

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