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. How to make my application to read and write files from installed directory c:\Program Files(x86)\appfolder\
Forum Update on Monday, May 27th 2025

How to make my application to read and write files from installed directory c:\Program Files(x86)\appfolder\

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 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.
  • M Offline
    M Offline
    Maikkannan
    wrote on last edited by VRonin
    #1

    Hi All,
    I'm making GUI application using Qt creator 4.9.0 and Qt library 5.12.2 (MSVC 2017, 32 bit) in windows 10 system.

    My application works well. I need to read and write in a file which is located in installed directory C:\Program Files(x86)\appfolder. How can I make it possible?

    I'm using qt installer framework to build the installer. Windows OS asks admin permission while installing my application. it pretty good. But application couldn't read/write into the file which is in installed directory.

    Thanks.

    JonBJ 1 Reply Last reply
    0
    • M Maikkannan

      Hi All,
      I'm making GUI application using Qt creator 4.9.0 and Qt library 5.12.2 (MSVC 2017, 32 bit) in windows 10 system.

      My application works well. I need to read and write in a file which is located in installed directory C:\Program Files(x86)\appfolder. How can I make it possible?

      I'm using qt installer framework to build the installer. Windows OS asks admin permission while installing my application. it pretty good. But application couldn't read/write into the file which is in installed directory.

      Thanks.

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

      @Maikkannan
      Please clarify:

      But application couldn't read/write into the file which is in installed directory.

      Do you mean that at install time, or do you mean after installing successfully then at run-time your app lacks permission to write into that directory?

      Because if it's that, so far as I understand a (non-elevated) Windows app these days is not supposed or allowed to write into C:\Program Files(x86)\appfolder\. That's no longer what you're supposed to do, so why do you need to? Look at the Qt paths to other directories which will show you one where where you are supposed to write e.g. run-time user data.

      M 1 Reply Last reply
      1
      • JonBJ JonB

        @Maikkannan
        Please clarify:

        But application couldn't read/write into the file which is in installed directory.

        Do you mean that at install time, or do you mean after installing successfully then at run-time your app lacks permission to write into that directory?

        Because if it's that, so far as I understand a (non-elevated) Windows app these days is not supposed or allowed to write into C:\Program Files(x86)\appfolder\. That's no longer what you're supposed to do, so why do you need to? Look at the Qt paths to other directories which will show you one where where you are supposed to write e.g. run-time user data.

        M Offline
        M Offline
        Maikkannan
        wrote on last edited by
        #3

        Hi @JonB,
        Thanks for the reply.
        " That's no longer what you're supposed to do, so why do you need to? " : To store my log data in C:\Program Files(x86)\appfolder. I though it will be safe and cannot be accessed by some other programs.
        " Look at the Qt paths to other directories " : sure. I looking with C:\Users\username\AppData\Roaming or C:\Users\username\AppData\Local or C:\Users\username\AppData\LocalLow.

        JonBJ 1 Reply Last reply
        0
        • M Maikkannan

          Hi @JonB,
          Thanks for the reply.
          " That's no longer what you're supposed to do, so why do you need to? " : To store my log data in C:\Program Files(x86)\appfolder. I though it will be safe and cannot be accessed by some other programs.
          " Look at the Qt paths to other directories " : sure. I looking with C:\Users\username\AppData\Roaming or C:\Users\username\AppData\Local or C:\Users\username\AppData\LocalLow.

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

          @Maikkannan said in How to make my application to read and write files from installed directory c:\Program Files(x86)\appfolder\:

          To store my log data in C:\Program Files(x86)\appfolder. I though it will be safe and cannot be accessed by some other programs.

          It cannot be (write) accessed by your program either! (Unless you run elevated, which you don't want to do. The installer does, so it can put stuff there, but your app should not when it is run.)

          Yes, use one of the paths Qt makes available from https://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum (don't hard-code). Probably one of the QStandardPaths::App... ones.

          1 Reply Last reply
          5
          • M Offline
            M Offline
            Maikkannan
            wrote on last edited by
            #5

            Sure. I think it will work. I will try with this QStandardPaths::App...

            Thanks.

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              You can get the directory path via https://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath
              Permissioning, however, is a totally different topic

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              JonBJ 1 Reply Last reply
              2
              • VRoninV VRonin

                You can get the directory path via https://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath
                Permissioning, however, is a totally different topic

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

                @VRonin
                Yes, but before the OP gets confused, we are saying that is not the place to try to save stuff when the application is running, which is what he is asking about ("I need to read and write in a file")...

                artwawA 1 Reply Last reply
                1
                • JonBJ JonB

                  @VRonin
                  Yes, but before the OP gets confused, we are saying that is not the place to try to save stuff when the application is running, which is what he is asking about ("I need to read and write in a file")...

                  artwawA Offline
                  artwawA Offline
                  artwaw
                  wrote on last edited by
                  #8

                  @JonB Simple answer to that will be "run as admin" - but, as stated above - this is something you should not do.

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  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