Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



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



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



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



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



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

    Thanks.



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



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



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


Log in to reply