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. Weird result with QSettings access error
Forum Updated to NodeBB v4.3 + New Features

Weird result with QSettings access error

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 900 Views
  • 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.
  • L Offline
    L Offline
    Loic B.
    wrote on last edited by Loic B.
    #1

    Hello,

    I do not understand the result of the QSettings::status() function in this case:

    I have a system and user scope settings file. When I remove the rights to write in the system scope file, the next time I use the user scope settings, I get an QSettings::AccessError when I call the status function. However, when I open the user scope file, the value has been written even with the error status

    On the opposite, if I remove the rights to write in the user scope file, I get errors only when trying to write in the user scope settings.

    Why the status is always at AccessError when the system scope in not writable ?

    Here is a minimal reproducible code:

    #include <QSettings>
    #include <QDebug>
    
    void printStatus(const QSettings& settings)
    {
        switch (settings.status()) {
        case QSettings::NoError:
            qInfo() << settings.scope() << "No error";
            break;
        case QSettings::AccessError:
            qInfo() << settings.scope() << "Access error";
            break;
        case QSettings::FormatError:
            qInfo() << settings.scope() << "Format error";
            break;
        default:
            break;
        }
    }
    
    void testSettings(QSettings::Scope scope, int value)
    {
        QSettings settings { QSettings::IniFormat, scope, "TestQSettings", "TestQSettings" };
        settings.sync();
        printStatus(settings);
    
        settings.setValue("test", value);
        settings.sync();
        printStatus(settings);
    }
    
    int main(int argc, char *argv[])
    {
        testSettings(QSettings::UserScope, 40);
    
        testSettings(QSettings::SystemScope, 40);
    
        testSettings(QSettings::UserScope, 42);
    
        testSettings(QSettings::SystemScope, 42);
    }
    

    And this is what I obtain when the system scope file only is not writable:

    QSettings::UserScope No error
    QSettings::UserScope No error
    QSettings::SystemScope No error
    QSettings::SystemScope Access error
    QSettings::UserScope Access error
    QSettings::UserScope Access error
    QSettings::SystemScope Access error
    QSettings::SystemScope Access error
    

    My system settings:

    • Windows 10
    • MSVC 2019
    • Qt 5.15.2
    1 Reply Last reply
    0
    • L Offline
      L Offline
      Loic B.
      wrote on last edited by Loic B.
      #2

      I also reproduced this behavior with Qt 6.2.4

      This bug seems to match with what I encountered but even by creating a new QSettings, the problem remains.

      JonBJ 1 Reply Last reply
      0
      • L Loic B.

        I also reproduced this behavior with Qt 6.2.4

        This bug seems to match with what I encountered but even by creating a new QSettings, the problem remains.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #3

        @Loic-B
        Did you at least try calling QSettings::sync() after the first error, to see whether that clears it?

        L 1 Reply Last reply
        0
        • JonBJ JonB

          @Loic-B
          Did you at least try calling QSettings::sync() after the first error, to see whether that clears it?

          L Offline
          L Offline
          Loic B.
          wrote on last edited by
          #4

          @JonB it does the same thing.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Loic B.
            wrote on last edited by
            #5

            Is someone has been able to reproduce this behavior ?

            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