Search code examples
qtqsettings

Settings.ini in same folder as application is write protect


I made a little tool application and it accesses Settings.ini via QSettings. The ini file I put in the same directory as the application itself. But when I try to write to it using the application, it seems to be blocked due to no admin access. I am guessing the Program Files (x86) folder is offlimits to write? Thus how do I solve this issue?


Solution

  • You guess correctly, it is most likely a permission problem. Typically user settings files go into a user-accessible folder separate from the application itself, for example C:\Users\<Username>\AppData\Roaming\Company\Application.ini on Windows.

    All you really need to enable a .ini settings file for your application is something like this (from QSettings docs):

    QSettings settings("MySoft", "Star Runner");
    QSettings::setDefaultFormat(QSettings::IniFormat);
    

    On Windows this will automatically create/use: C:\Users\<Username>\AppData\Roaming\MySoft\Star Runner.ini for all future QSettings calls.

    (And works automatically on other platforms as well.)