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

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 1 Watching
  • 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 4 Mar 2020, 10:11 last edited by VRonin 3 Apr 2020, 12:17
    #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.

    J 1 Reply Last reply 4 Mar 2020, 10:26
    0
    • M Maikkannan
      4 Mar 2020, 10:11

      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.

      J Offline
      J Offline
      JonB
      wrote on 4 Mar 2020, 10:26 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 4 Mar 2020, 11:39
      1
      • J JonB
        4 Mar 2020, 10:26

        @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 4 Mar 2020, 11:39 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.

        J 1 Reply Last reply 4 Mar 2020, 11:45
        0
        • M Maikkannan
          4 Mar 2020, 11:39

          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.

          J Offline
          J Offline
          JonB
          wrote on 4 Mar 2020, 11:45 last edited by JonB 3 Apr 2020, 11:46
          #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 4 Mar 2020, 12:18 last edited by
            #5

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

            Thanks.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VRonin
              wrote on 4 Mar 2020, 12:19 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

              J 1 Reply Last reply 4 Mar 2020, 12:22
              2
              • V VRonin
                4 Mar 2020, 12:19

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

                J Offline
                J Offline
                JonB
                wrote on 4 Mar 2020, 12:22 last edited by JonB 3 Apr 2020, 12:23
                #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")...

                A 1 Reply Last reply 4 Mar 2020, 13:25
                1
                • J JonB
                  4 Mar 2020, 12:22

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

                  A Offline
                  A Offline
                  artwaw
                  wrote on 4 Mar 2020, 13:25 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

                  7/8

                  4 Mar 2020, 12:22

                  • Login

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