Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSettings. setPath with systemScope ignores userScope
Qt 6.11 is out! See what's new in the release blog

QSettings. setPath with systemScope ignores userScope

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 5.7k Views 1 Watching
  • 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 Offline
    E Offline
    egil
    wrote on last edited by
    #1

    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
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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
      0
      • E Offline
        E Offline
        egil
        wrote on last edited by
        #3

        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
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved