How to always get "C:\ProgramData" type location from QStandardPaths ...

  • Hello,

    I am in need of getting the standard configuration directory that my application can write to system-wide.

    I have the following code snippet that sort of works for this purpose, with one major problem:

    QStandardPaths* PathsToStandardLocations;

    QStringList FolderPaths = PathsToStandardLocations->standardLocations(QStandardPaths::ConfigLocation);

    GLint NumberOfPaths = FolderPaths.count();

    std::string CompletePath = FolderPaths[1].toStdString();

    So, I get the configuration as requested, EXCEPT I get four (4) locations back, with some of them being user directory locations!

    Is there something I am missing with QStandardPaths? How can I get JUST the system-wide location that my application can write to without generally worrying about permission stuff for all users?

    Thank you.

  • The documentation is clear on the QStandardPaths::ConfigLocation:

    bq. Returns a directory location where user-specific configuration files should be written. This may be either a generic value or application-specific, and the returned path is never empty.

    Also, very important note:

    bq. The first path is the writable path (unless noted). Other, additional paths, if any, represent non-writable locations

    The thing is in modern OSes there is no such thing as "without worrying about permission stuff for all users". A user is always logged in with certain permissions and your app always runs as a specific user and you do have to worry about that. Most of the "standard paths" are thus user-specific.
    The ProgramData (which can be located anywhere really) folder is not always accessible to all users. It's a location where a user with administrative privileges can setup a folder with permissions it chooses. This is usually done by the installer.
    If you want a single, writable location for the running app use writableLocation() instead of standardLocations().

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.