Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    QSettings. setPath with systemScope ignores userScope

    General and Desktop
    2
    4
    4984
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      egil last edited by

      I want to have my applications and system .ini-files on a network disk. These program lines are in the main.cpp-file:

      QCoreApplication::setOrganizationName("MyOrganization");
      QCoreApplication::setApplicationName("MyApp");
      QSettings::setDefaultFormat(QSettings::IniFormat);
      QSettings::setPath(QSettings::IniFormat,QSettings::SystemScope,QCoreApplication::applicationDirPath());
      

      The directory C:/Documents and Settings/myUser/Programdata/MyOrganization (%APPDATA%) contains a MyApp.ini-file.
      But the application reads the settings information from the directory ...applicationDirPath/MyOrganization on the network disk, which is specified for SystemScope in setPath. The function settingsObject.scope() in MyApp reports QSettings::UserScope.
      I want to use the system MyApp.ini-file as a fallback, and userScope writing to be done to the userScope %APPDATA%/MyApp.ini-file on the local disk. A common user should not be allowed to do writing to the system .ini-file. The way I understand the QSettings documentation (http://doc.trolltech.com/4.7/qsettings.html#setPath) my program should work that way.
      Have I missed something ??

      1 Reply Last reply Reply Quote 0
      • G
        goetz last edited by

        settingsObject.scope() returns the scope where settings will be written, that's not necessarily the scope where settings are read.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • E
          egil last edited by

          Perhaps I did not make myself quite clear. I use Windows XP and QtCreator 2.0.1. When I do not use setPath, QSettings reads from and writes to the %%APPDATA%% .ini-file. When I have called setPath with SystemScope, QSettings (in UserScope mode) afterwards ignores %%APPDATA%% and reads and writes from applicationDirPath. That is not the way I understand the documentation. Are there another way to ensure that the .ini-file at applicationDirPath is only read from as fallback (when the %%APPDATA%% .ini-file does not contain the relevant key), and that the %%APPDATA%% .ini-file (and not the applicationDirPath .ini-file) is written to in UserScope ?

          1 Reply Last reply Reply Quote 0
          • G
            goetz last edited by

            It could be that the system ini file is only read when there is no user file at all. I did not try this before.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply Reply Quote 0
            • First post
              Last post