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

QSettings access issue



  • Hi
    I am using QSettings class to configure my applications' startup behavior under Windows OS, but my application won't load the INI file unless I run my app as administrator. I am not sure if this is a system security level issue or I have to configure my APP somehow to let OS trust my application? Thanks for the help.



  • @junzhe-fan Where is the ini file located? If together with executable OS will not allow access. Please consider QStandardPaths which are OS aware and point to safe locations.



  • Where is your app located? That dir may be a better place to save the file because it goes with your app. In other dirs, this file could be cleaned up by accident.



  • @artwaw said in QSettings access issue:

    QStandardPaths

    @artwaw Hi it in C:\Program Files folder and under the same dirctory as my exe file



  • @junzhe-fan You should:

    1. read the documentation to QStandardPaths;
    2. having read that, please consider using location pointed by QStandardPaths::AppConfigLocation.


  • @artwaw QStandardPaths::AppConfigLocation is the optimal one.



  • @junzhe-fan said in QSettings access issue:

    Hi it in C:\Program Files folder and under the same dirctory as my exe file

    Just so you know. Used to be fine years ago. Now C:\Program Files\... (and the (x86) one) are no longer writable by users without admin elevation as a security guard. QSettings by default accesses .ini file for write as well as read, assuming you want to allow settings to be altered by user (do you?). So that's why it's best for you to put the file elsewhere and presumably causes your error situation. Much better than raising elevation on your program to permit it to write there.

    Or let QSettings use its default behaviour of using the Windows Registry, then this would not be an issue....


Log in to reply