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

Save a file in the same directory as QSettings



  • Dear all,
    I'm using QSettings for my applications and I choose to save in as a ini file instead off using the registry.
    Depending on the running system, it will be saved in a specific directory.

    Now I would like to save another file in the very same filder. So I need to be able to build the path on my own.
    I tried to look at QSettings.cpp source code but I can't find how to build this path.

    Thanks a lot for your help!



  • Ok I found my answer:
    @QString settingsPath = QFileInfo(settings.fileName()).absolutePath();@



  • That path is usually the wrong one. Use QDesktopServices::DataLocation for such stuff!



  • Why is this path wrong?
    On win7, qsettings are stored in appData/Roaming while QDesktopServices::DataLocation points to appData/Local



  • Saving arbitrary data in a preferences folder is wrong. Such data belongs elsewhere. These methods are there for a reason.

    The problem with roaming/local on Windows 7 might be fixed in a future release. Is there a bug report open? Would be good, to brings that to the Troll's attention.



  • What path is returned, if you sue QSettinsg with native format on windows? The settings are then stored in the registry...



  • [quote author="Gerolf" date="1308499376"]What path is returned, if you sue QSettinsg with native format on windows? The settings are then stored in the registry...[/quote]

    According to API docs:

    bq. On Windows, if the format is QSettings::NativeFormat, the return value is a system registry path, not a file path.



  • Are you sure it is a bug?
    [quote author="Volker" date="1308498317"]The problem with roaming/local on Windows 7 might be fixed in a future release. Is there a bug report open? Would be good, to brings that to the Troll's attention.[/quote]



  • Feature requests are in the "bug" tracker too :-)



  • I can understand this. However I don't know what I should request. I just said
    [quote author="neFAST" date="1307718701"]On win7, qsettings are stored in appData/Roaming while QDesktopServices::DataLocation points to appData/Local[/quote] but is it a bug? What should be the correct behavior?



  • [quote author="neFAST" date="1308696036"]I can understand this. However I don't know what I should request. I just said
    [quote author="neFAST" date="1307718701"]On win7, qsettings are stored in appData/Roaming while QDesktopServices::DataLocation points to appData/Local[/quote] but is it a bug? What should be the correct behavior?[/quote]

    I do not have an idea. I would have to read on that topic first. Maybe some googling gives you more information. Sorry that I cannot give you a more useful answer.


Log in to reply