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 file location in Ubuntu ambiguous?
Forum Updated to NodeBB v4.3 + New Features

QSettings file location in Ubuntu ambiguous?

Scheduled Pinned Locked Moved Solved General and Desktop
31 Posts 5 Posters 4.8k Views 2 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.
  • B Bengt 0

    Thanks.
    Your suggestion gives me the user scope, not the admin scope.
    My problem is the admin.

    BTW, what doc are you referring to?
    I am using the QAssistant. Can it be trusted?

    M Offline
    M Offline
    mpergand
    wrote on last edited by
    #5

    @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

    BTW, what doc are you referring to?

    https://doc.qt.io/qt-6/qstandardpaths.html

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bengt 0
      wrote on last edited by
      #6

      Ok, it seems none of the standard paths enums will give me /etc/xdg.
      At best, they will give me the user-specific prefs location(s).
      Any other suggestion?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bengt 0
        wrote on last edited by
        #7

        Ok, QStringList::StandardPaths::standardLocations() is giving me a list of possible candidates. However, it will not tell me which location QSettings admin scope is actually using.
        It is also clear that QSettings::fileName() is not doing what it claims to do. Why is it there?

        Not SOLVED yet.

        jsulmJ JonBJ 2 Replies Last reply
        0
        • B Bengt 0

          Ok, QStringList::StandardPaths::standardLocations() is giving me a list of possible candidates. However, it will not tell me which location QSettings admin scope is actually using.
          It is also clear that QSettings::fileName() is not doing what it claims to do. Why is it there?

          Not SOLVED yet.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

          It is also clear that QSettings::fileName() is not doing what it claims to do

          What is it doing instead?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • B Bengt 0

            Ok, QStringList::StandardPaths::standardLocations() is giving me a list of possible candidates. However, it will not tell me which location QSettings admin scope is actually using.
            It is also clear that QSettings::fileName() is not doing what it claims to do. Why is it there?

            Not SOLVED yet.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #9

            @Bengt-0
            I don't if this helps, but I looked at my Ubuntu system, which I presume is similar to your Lubuntu, and found the following equivalents to your situation:

            # echo $XDG_CONFIG_DIRS
            /etc/xdg/xdg-ubuntu:/etc/xdg
            # ls /etc/xdg/xdg-ubuntu
            ls: cannot access '/etc/xdg/xdg-ubuntu': No such file or directory
            # ls /etc/xdg
            autostart  systemd         user-dirs.defaults
            menus      user-dirs.conf  Xwayland-session.d
            

            Sooo.... /etc/xdg/xdg-ubuntu in $XDG_CONFIG_DIRS does not actually exist. Same for your /etc/xdg/xdg-Lubuntu? So I'm thinking that directory is not used, only the second one, /etc/xdg is actually in use.

            Does that help any? Do you have a /etc/xdg/xdg-Lubuntu? If you do, is it perchance a symbolic link to .. or /etc/xdg?

            B 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

              It is also clear that QSettings::fileName() is not doing what it claims to do

              What is it doing instead?

              B Offline
              B Offline
              Bengt 0
              wrote on last edited by
              #10

              @jsulm
              My prefs are saved at /etc/xdg/myOrg/MYAPP.INI, checked and verified.
              QSettings::fileName() replies /etc/xdg/xdg-Lubuntu/myOrg, which is not correct.

              1 Reply Last reply
              0
              • JonBJ JonB

                @Bengt-0
                I don't if this helps, but I looked at my Ubuntu system, which I presume is similar to your Lubuntu, and found the following equivalents to your situation:

                # echo $XDG_CONFIG_DIRS
                /etc/xdg/xdg-ubuntu:/etc/xdg
                # ls /etc/xdg/xdg-ubuntu
                ls: cannot access '/etc/xdg/xdg-ubuntu': No such file or directory
                # ls /etc/xdg
                autostart  systemd         user-dirs.defaults
                menus      user-dirs.conf  Xwayland-session.d
                

                Sooo.... /etc/xdg/xdg-ubuntu in $XDG_CONFIG_DIRS does not actually exist. Same for your /etc/xdg/xdg-Lubuntu? So I'm thinking that directory is not used, only the second one, /etc/xdg is actually in use.

                Does that help any? Do you have a /etc/xdg/xdg-Lubuntu? If you do, is it perchance a symbolic link to .. or /etc/xdg?

                B Offline
                B Offline
                Bengt 0
                wrote on last edited by
                #11

                @JonB

                I have /etc/xdg/xdg-Lubuntu, but it is not empty.
                It contains some other stuff presumably for other applications.
                And as said, my real prefs are stored at /etc/xdg/myOrg.
                I have been able to apply a fix by making a symlink /etc/xdg/xdg-Lubuntu/myOrg -> /etc/xdg/myOrg.
                But I think this is an ugly solution.

                My real problem is that I want to make an app installer for other users (open source LPGL), and then things like this are clearly undesirable. A more stable solution would be better.

                But since
                ~$ echo $XDG_CONFIG_DIRS
                /etc/xdg/xdg-Lubuntu:/etc/xdg:/etc:/usr/share
                lists several config directories, I feel there should be a standard way of handling this.
                But I do not know what it is.

                BN

                JonBJ 1 Reply Last reply
                0
                • B Bengt 0

                  @JonB

                  I have /etc/xdg/xdg-Lubuntu, but it is not empty.
                  It contains some other stuff presumably for other applications.
                  And as said, my real prefs are stored at /etc/xdg/myOrg.
                  I have been able to apply a fix by making a symlink /etc/xdg/xdg-Lubuntu/myOrg -> /etc/xdg/myOrg.
                  But I think this is an ugly solution.

                  My real problem is that I want to make an app installer for other users (open source LPGL), and then things like this are clearly undesirable. A more stable solution would be better.

                  But since
                  ~$ echo $XDG_CONFIG_DIRS
                  /etc/xdg/xdg-Lubuntu:/etc/xdg:/etc:/usr/share
                  lists several config directories, I feel there should be a standard way of handling this.
                  But I do not know what it is.

                  BN

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #12

                  @Bengt-0
                  So that there can be no misunderstanding, can you please run the following two commands and paste the output:

                  ls -ld /etc/xdg/
                  ls -ld /etc/xdg/xdg-Lubuntu/
                  

                  QSettings::fileName() replies /etc/xdg/xdg-Lubuntu/myOrg, which is not correct.

                  Could you please supply the absolute minimum code to reproduce this, so that I/we can maybe copy & paste to see how it behaves for us. It would seem "surprising" for it not to report the actual file path it is using to access the file, one would assume it is using that path to open the .ini file.

                  lists several config directories, I feel there should be a standard way of handling this.

                  In what way? XDG_CONFIG_DIRS is not a Qt thing, it's a Linux/XDG thing. If they have a :-separated list of directories to look in then that is their affair.

                  B 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Bengt-0
                    So that there can be no misunderstanding, can you please run the following two commands and paste the output:

                    ls -ld /etc/xdg/
                    ls -ld /etc/xdg/xdg-Lubuntu/
                    

                    QSettings::fileName() replies /etc/xdg/xdg-Lubuntu/myOrg, which is not correct.

                    Could you please supply the absolute minimum code to reproduce this, so that I/we can maybe copy & paste to see how it behaves for us. It would seem "surprising" for it not to report the actual file path it is using to access the file, one would assume it is using that path to open the .ini file.

                    lists several config directories, I feel there should be a standard way of handling this.

                    In what way? XDG_CONFIG_DIRS is not a Qt thing, it's a Linux/XDG thing. If they have a :-separated list of directories to look in then that is their affair.

                    B Offline
                    B Offline
                    Bengt 0
                    wrote on last edited by
                    #13

                    @JonB
                    ~$ ls -ld /etc/xdg
                    drwxr-xr-x 12 root root 4096 Oct 6 21:07 /etc/xdg
                    ~$ ls -ld /etc/xdg/xdg-Lubuntu
                    drwxr-xr-x 9 root root 4096 Oct 6 21:16 /etc/xdg/xdg-Lubuntu

                    I will try to make a minimal code example.

                    The last comment is perhaps not a Qt thing.
                    Or is XDG_CONFIG_DIRS a Qt related environmental?
                    I am just curious that it seems to offer multiple possibilities of config paths, and I am ignorant of how to use this feature in practice.

                    JonBJ 1 Reply Last reply
                    0
                    • B Bengt 0

                      @JonB
                      ~$ ls -ld /etc/xdg
                      drwxr-xr-x 12 root root 4096 Oct 6 21:07 /etc/xdg
                      ~$ ls -ld /etc/xdg/xdg-Lubuntu
                      drwxr-xr-x 9 root root 4096 Oct 6 21:16 /etc/xdg/xdg-Lubuntu

                      I will try to make a minimal code example.

                      The last comment is perhaps not a Qt thing.
                      Or is XDG_CONFIG_DIRS a Qt related environmental?
                      I am just curious that it seems to offer multiple possibilities of config paths, and I am ignorant of how to use this feature in practice.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #14

                      @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

                      Or is XDG_CONFIG_DIRS a Qt related environmental?

                      No. Qt is using it, but does not set it, it is not a Qt creation. But Qt code might do the picking from the :-list directories or set fileName() not to what you say it should do, I do not know.

                      https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
                      https://askubuntu.com/questions/1179729/where-is-xdg-config-dirs-set

                      $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory.

                      XDG is to do with your desktop.

                      If you want a one-page overview of what this is about, https://maex.me/2019/12/the-power-of-the-xdg-base-directory-specification/ seems simple.

                      B 1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        ChrisW67
                        wrote on last edited by
                        #15

                        @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

                        ~$ ls -ld /etc/xdg
                        drwxr-xr-x 12 root root 4096 Oct 6 21:07 /etc/xdg
                        ~$ ls -ld /etc/xdg/xdg-Lubuntu
                        drwxr-xr-x 9 root root 4096 Oct 6 21:16 /etc/xdg/xdg-Lubuntu

                        OK, so neither location is writable to a non-root user. I assume your application is not running as root. When you ask Qt for:

                        QString path=QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
                        

                        it will not give you either of those locations because they are not writable.

                        I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.

                        Your user-specific. modifiable application configuration files should be in:
                        QStandardPaths::ConfigLocation or QStandardPaths::AppConfigLocation (On Linux under ~/.config)

                        Along with my settings INI file, I want to store a log file at the same location.

                        That is very poor place to place a log file. For a system-wide tool the appropriate place would be /var/log (or use syslog). See Filesystem Hierarchy Standard (FHS) for more.

                        If your application log file is for user consumption, then it should go somewhere the user defines.
                        If your application log file is for debugging or similar use then you could use
                        QStandardPaths::AppDataLocation or QStandardPaths::AppLocalDataLocation (Windows)
                        If your application log file is for temporary purposes only then
                        QStandardPaths::TempLocation

                        B 1 Reply Last reply
                        2
                        • C ChrisW67

                          @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

                          ~$ ls -ld /etc/xdg
                          drwxr-xr-x 12 root root 4096 Oct 6 21:07 /etc/xdg
                          ~$ ls -ld /etc/xdg/xdg-Lubuntu
                          drwxr-xr-x 9 root root 4096 Oct 6 21:16 /etc/xdg/xdg-Lubuntu

                          OK, so neither location is writable to a non-root user. I assume your application is not running as root. When you ask Qt for:

                          QString path=QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
                          

                          it will not give you either of those locations because they are not writable.

                          I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.

                          Your user-specific. modifiable application configuration files should be in:
                          QStandardPaths::ConfigLocation or QStandardPaths::AppConfigLocation (On Linux under ~/.config)

                          Along with my settings INI file, I want to store a log file at the same location.

                          That is very poor place to place a log file. For a system-wide tool the appropriate place would be /var/log (or use syslog). See Filesystem Hierarchy Standard (FHS) for more.

                          If your application log file is for user consumption, then it should go somewhere the user defines.
                          If your application log file is for debugging or similar use then you could use
                          QStandardPaths::AppDataLocation or QStandardPaths::AppLocalDataLocation (Windows)
                          If your application log file is for temporary purposes only then
                          QStandardPaths::TempLocation

                          B Offline
                          B Offline
                          Bengt 0
                          wrote on last edited by
                          #16

                          @ChrisW67
                          Chris,

                          I have a very good reason to put my log and config, and settings in a system-scope folder.
                          The software is driving a measurement system, to be configured and calibrated by a maintenance engineer as root user. The system config, calibration data and log of the accuracy are valuable and should not be risked of loss.

                          Actually, what I call a "log file" might not qualify exactly as a log file in the regular sense. It is more of a receipt of a calibration operation, describing parameters used and the result of the calibration. This is done on a monthly basis, and it is desirable to have long term a history available of the equipment performance. To my (limited) experience, /var/log can be a pretty wild and crowded place, important things might be lost there.

                          The system is used daily by regular non-root users, and the user-scope prefs are placed in a standard user pref location. If the software binaries are updated, the config, calibration data and calibration logs are not touched. If a regular user is making a serious mistake, the config and calibration data are still safe.
                          So my requirements are a bit special.

                          BN

                          1 Reply Last reply
                          0
                          • JonBJ JonB

                            @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

                            Or is XDG_CONFIG_DIRS a Qt related environmental?

                            No. Qt is using it, but does not set it, it is not a Qt creation. But Qt code might do the picking from the :-list directories or set fileName() not to what you say it should do, I do not know.

                            https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
                            https://askubuntu.com/questions/1179729/where-is-xdg-config-dirs-set

                            $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory.

                            XDG is to do with your desktop.

                            If you want a one-page overview of what this is about, https://maex.me/2019/12/the-power-of-the-xdg-base-directory-specification/ seems simple.

                            B Offline
                            B Offline
                            Bengt 0
                            wrote on last edited by
                            #17

                            @JonB
                            Ok, so it is similar to the PATH variable.
                            Searching for available binary applications by walking they the PATH list is quite logical, but doing the same for config files is less obvious. At least to me, but I get the idea. Thanks.

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              ChrisW67
                              wrote on last edited by
                              #18

                              Alright. You want to use the fallback mechanism to achieve this.

                              When the application is run effectively as root and you go to save the global configuration, calibration data etc. then you should use QSettings(QSettings::SystemScope). In that case the settings will go under /etc/xdg by default. Write the shared settings into a group named e.g., "Global".

                              When the application is not run as root (the vast majority of time), open QSettings (QSettings::UserScope).
                              User-specific settings should be written to and read from a group called e.g., "User", to avoid any potential for collision.
                              When the user reads from group "Global" they will see the the central configuration file because of the fallback mechanism. The user mode code should never call setValue() on values in the "Global" group because that will create settings locally that will then mask the central ones.

                              #include <QCoreApplication>
                              #include <QSettings>
                              #include <QDateTime>
                              #include <QDebug>
                              
                              #include <unistd.h>
                              #include <sys/types.h>
                              
                              
                              int main(int argc, char *argv[])
                              {
                                  QCoreApplication a(argc, argv);
                              
                                  QCoreApplication::setOrganizationName("Example");
                                  QCoreApplication::setOrganizationDomain("example.com");
                                  QCoreApplication::setApplicationName("Test");
                              
                                  uid_t euid = geteuid();
                                  if (euid == 0) {
                                      QSettings settings(QSettings::SystemScope);
                                      qDebug() << "Running as root:" << settings.fileName();
                              
                                      // System-wide settings should only ever be written in here
                                      settings.beginGroup("Global");
                                      settings.setValue("LastChange", QDateTime::currentDateTimeUtc().toString(Qt::ISODate));
                                      settings.setValue("Calibration", 36);
                                      settings.endGroup();
                                  }
                                  else {
                                        QSettings settings(QSettings::UserScope);
                                        qDebug() << "Running as user:" << settings.fileName();
                              
                                        // System-wide settings are visible and read-only in here
                                        qDebug() << "Global last change:" << settings.value("Global/LastChange");
                                        qDebug() << "Global Calibration:" << settings.value("Global/Calibration");
                              
                                        // User-specific settings can be read/write in here
                                        qDebug() << "User last change:" << settings.value("User/LastChange");
                                        qDebug() << "User fun count  :" << settings.value("User/AmountOfMeasurementFun");
                              
                                        settings.beginGroup("User");
                                        settings.setValue("LastChange", QDateTime::currentDateTimeUtc().toString(Qt::ISODate));
                                        int funCount = settings.value("AmountOfMeasurementFun", 0).toInt();
                                        settings.setValue("AmountOfMeasurementFun", ++funCount);
                                        settings.endGroup();
                                  }
                              
                                  return 0;
                              }
                              

                              Tests:

                              $ ls -ld /etc/xdg/Example ~/.config/Example
                              ls: cannot access '/etc/xdg/Example': No such file or directory
                              ls: cannot access '/home/chrisw/.config/Example': No such file or directory
                              $ ./test 
                              Running as user: "/home/chrisw/.config/Example/Test.conf"
                              Global last change: QVariant(Invalid)
                              Global Calibration: QVariant(Invalid)
                              User last change: QVariant(Invalid)
                              User fun count  : QVariant(Invalid)
                              

                              There was no system config but a user config has now been written:

                              $ cat /home/chrisw/.config/Example/Test.conf
                              [User]
                              AmountOfMeasurementFun=1
                              LastChange=2022-10-08T02:22:24Z
                              
                              

                              Now a calibration session is run as root:

                              $ sudo ./test
                              Running as root: "/etc/xdg/Example/Test.conf"
                              $ cat /home/chrisw/.config/Example/Test.conf
                              [User]
                              AmountOfMeasurementFun=1
                              LastChange=2022-10-08T02:22:24Z
                              $ cat /etc/xdg/Example/Test.conf 
                              [Global]
                              Calibration=36
                              LastChange=2022-10-08T02:22:48Z
                              

                              The user settings unchanged but now the system settings exist, the user sees them.

                              $ ./test 
                              Running as user: "/home/chrisw/.config/Example/Test.conf"
                              Global last change: QVariant(QString, "2022-10-08T02:22:48Z")
                              Global Calibration: QVariant(QString, "36")
                              User last change: QVariant(QString, "2022-10-08T02:22:24Z")
                              User fun count  : QVariant(QString, "1")
                              $ ./test 
                              Running as user: "/home/chrisw/.config/Example/Test.conf"
                              Global last change: QVariant(QString, "2022-10-08T02:22:48Z")
                              Global Calibration: QVariant(QString, "36")
                              User last change: QVariant(QString, "2022-10-08T02:23:08Z")
                              User fun count  : QVariant(QString, "2")
                              

                              The global settings are never in the user's configuration file.

                              $ cat /home/chrisw/.config/Example/Test.conf
                              [User]
                              AmountOfMeasurementFun=3
                              LastChange=2022-10-08T02:23:29Z
                              
                              1 Reply Last reply
                              2
                              • B Bengt 0

                                Hi,

                                In my Lubuntu application, I am using QSettings IniFormat.
                                I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.
                                Along with my settings INI file, I want to store a log file at the same location.
                                In a different section of my program, I use QSettings::fileName() to find the path to the log file.
                                However, the file path from ::fileName is instead /etc/xdg/xdg-Lubuntu/myOrg, not /etc/xdg/myOrg.
                                So of course I fail to open my log file using this path.

                                Why is this?
                                Can it be corrected?
                                I am hesitant to "hack" this myself since this can have unexpected consequences.
                                If it is a bug it might even be corrected, and then my program might fail anyway after an update.:)

                                BN

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #19

                                @Bengt-0
                                Firstly, please read through @ChrisW67's very thorough sample code in his last post.

                                Going back to your original question/"bad" behaviour:

                                I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.

                                Along with my settings INI file, I want to store a log file at the same location.

                                In a different section of my program, I use QSettings::fileName() to find the path to the log file.

                                However, the file path from ::fileName is instead /etc/xdg/xdg-Lubuntu/myOrg, not /etc/xdg/myOrg.

                                I do not get this. In particular I do not get your "I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.". And I don't know how exactly this comes about for you, since you showed

                                ~$ ls -ld /etc/xdg
                                drwxr-xr-x 12 root root 4096 Oct 6 21:07 /etc/xdg
                                

                                Since /etc/xdg is writable only by root, how did you get /etc/xdg/myOrg/ and what are its permissions/who is it writable by?

                                Here is the test code I used:

                                #include <QCoreApplication>
                                #include <QDebug>
                                #include <QSettings>
                                
                                int main(int argc, char *argv[])
                                {
                                    QCoreApplication a(argc, argv);
                                
                                    QCoreApplication::setOrganizationName("Example");
                                    QCoreApplication::setOrganizationDomain("example.com");
                                    QCoreApplication::setApplicationName("Settings");
                                
                                    QSettings userSettings(QSettings::UserScope, "Example", "Settings");
                                    qDebug() << userSettings.fileName();
                                    userSettings.setValue("abc", "def");
                                    userSettings.sync();
                                    qDebug() << userSettings.status();
                                
                                    QSettings systemSettings(QSettings::SystemScope, "Example", "Settings");
                                    qDebug() << systemSettings.fileName();
                                    systemSettings.setValue("abc", "def");
                                    systemSettings.sync();
                                    qDebug() << systemSettings.status();
                                
                                    return a.exec();
                                }
                                

                                [I have to use a slightly different QSettings constructor from you since I am on Qt 5.12, but it's the same effect.] Running as me, not root (is that your case too?). And my output is:

                                "/home/jon/.config/Example/Settings.conf"
                                QSettings::NoError
                                "/etc/xdg/xdg-ubuntu/Example/Settings.conf"
                                QSettings::AccessError
                                

                                just as I would expect.

                                B 2 Replies Last reply
                                0
                                • JonBJ JonB

                                  @Bengt-0
                                  Firstly, please read through @ChrisW67's very thorough sample code in his last post.

                                  Going back to your original question/"bad" behaviour:

                                  I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.

                                  Along with my settings INI file, I want to store a log file at the same location.

                                  In a different section of my program, I use QSettings::fileName() to find the path to the log file.

                                  However, the file path from ::fileName is instead /etc/xdg/xdg-Lubuntu/myOrg, not /etc/xdg/myOrg.

                                  I do not get this. In particular I do not get your "I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.". And I don't know how exactly this comes about for you, since you showed

                                  ~$ ls -ld /etc/xdg
                                  drwxr-xr-x 12 root root 4096 Oct 6 21:07 /etc/xdg
                                  

                                  Since /etc/xdg is writable only by root, how did you get /etc/xdg/myOrg/ and what are its permissions/who is it writable by?

                                  Here is the test code I used:

                                  #include <QCoreApplication>
                                  #include <QDebug>
                                  #include <QSettings>
                                  
                                  int main(int argc, char *argv[])
                                  {
                                      QCoreApplication a(argc, argv);
                                  
                                      QCoreApplication::setOrganizationName("Example");
                                      QCoreApplication::setOrganizationDomain("example.com");
                                      QCoreApplication::setApplicationName("Settings");
                                  
                                      QSettings userSettings(QSettings::UserScope, "Example", "Settings");
                                      qDebug() << userSettings.fileName();
                                      userSettings.setValue("abc", "def");
                                      userSettings.sync();
                                      qDebug() << userSettings.status();
                                  
                                      QSettings systemSettings(QSettings::SystemScope, "Example", "Settings");
                                      qDebug() << systemSettings.fileName();
                                      systemSettings.setValue("abc", "def");
                                      systemSettings.sync();
                                      qDebug() << systemSettings.status();
                                  
                                      return a.exec();
                                  }
                                  

                                  [I have to use a slightly different QSettings constructor from you since I am on Qt 5.12, but it's the same effect.] Running as me, not root (is that your case too?). And my output is:

                                  "/home/jon/.config/Example/Settings.conf"
                                  QSettings::NoError
                                  "/etc/xdg/xdg-ubuntu/Example/Settings.conf"
                                  QSettings::AccessError
                                  

                                  just as I would expect.

                                  B Offline
                                  B Offline
                                  Bengt 0
                                  wrote on last edited by
                                  #20

                                  @JonB
                                  Jon,

                                  I sense some possible miscommunication here.

                                  First, the listing of directory content.
                                  I am using "ls-la" and not "ls -ld":

                                  $ ls -la /etc/xdg/
                                  total 76
                                  drwxr-xr-x  13 root root  4096 Oct  8 12:15 .
                                  drwxr-xr-x 130 root root 12288 Oct  7 08:32 ..
                                  -rw-r--r--   1 root root    86 Mar  5  2022 accept-languages.codes
                                  drwxr-xr-x   2 root root  4096 Oct  7 08:00 autostart
                                  drwxr-xr-x   2 root root  4096 Oct  8 11:53 Example
                                  -rw-r--r--   1 root root   153 Mar  5  2022 kshorturifilterrc
                                  drwxr-xr-x   2 root root  4096 Aug  9 13:50 libfm
                                  drwxr-xr-x   3 root root  4096 Aug  9 13:49 lxqt
                                  drwxr-xr-x   2 root root  4096 Aug  9 13:51 menus
                                  drwxr-xr-x   2 root root  4096 Oct  8 12:37 MYORG
                                  drwxr-xr-x   2 root root  4096 Aug  9 13:50 openbox
                                  drwxr-xr-x   2 root root  4096 Aug  9 13:47 systemd
                                  drwxr-xr-x   2 root root  4096 Aug  9 13:50 ui
                                  -rw-r--r--   1 root root   414 Mar 25  2022 user-dirs.conf
                                  -rw-r--r--   1 root root   418 Mar 25  2022 user-dirs.defaults
                                  drwxr-xr-x   9 root root  4096 Aug  9 13:51 xdg-Lubuntu
                                  drwxr-xr-x   2 root root  4096 Aug  9 13:51 Xwayland-session.d
                                  
                                  $ ls -la /etc/xdg/MYORG
                                  total 12
                                  drwxr-xr-x  2 root root 4096 Oct  8 12:37 .
                                  drwxr-xr-x 13 root root 4096 Oct  8 12:15 ..
                                  -rw-r--r--  1 root root  227 Oct  8 12:37 MYAPP.ini
                                  
                                  $ ls -la /etc/xdg/xdg-Lubuntu/
                                  total 48
                                  drwxr-xr-x  9 root root 4096 Aug  9 13:51 .
                                  drwxr-xr-x 13 root root 4096 Oct  8 12:15 ..
                                  drwxr-xr-x  2 root root 4096 Aug  9 13:51 autostart
                                  drwxr-xr-x  2 root root 4096 Aug  9 13:51 libfm
                                  drwxr-xr-x  2 root root 4096 Aug  9 13:51 lxqt
                                  -rw-r--r--  1 root root 8468 Nov 14  2021 mimeapps.list
                                  drwxr-xr-x  2 root root 4096 Aug  9 13:51 nm-tray
                                  drwxr-xr-x  2 root root 4096 Aug  9 13:51 openbox
                                  drwxr-xr-x  3 root root 4096 Aug  9 13:49 pcmanfm-qt
                                  drwxr-xr-x  2 root root 4096 Aug  9 13:51 qterminal.org
                                  
                                  
                                  

                                  Here you can see that MYORG resides in /etc/xdg, and MYAPP.ini is in /etc/xdg/MYORG. /etc/xdg/xdg-Lubuntu does not contain any of my files.

                                  Now to the sample code, and this is interesting. Thanks for supplying the sample code, both of you, you were quicker than me.

                                  The sample code from @ChrisW67 works correctly. I tried it and got the same result.
                                  However, your code (JonB) reproduces my problem if I try it, and you also write this in your post.

                                  "/home/jon/.config/Example/Settings.conf"
                                  QSettings::NoError
                                  "/etc/xdg/xdg-ubuntu/Example/Settings.conf"
                                  QSettings::AccessError
                                  

                                  You seem to think this is ok and expected, you need to explain why to me.

                                  I would expect qDebug() << systemSettings.fileName(); to give "/etc/xdg/Example/Settings.conf".

                                  There is something I do not understand here.

                                  BN

                                  JonBJ 1 Reply Last reply
                                  0
                                  • C Offline
                                    C Offline
                                    ChrisW67
                                    wrote on last edited by
                                    #21

                                    @Bengt-0 said in QSettings file location in Ubuntu ambiguous?:

                                    You seem to think this is ok and expected, you need to explain why to me.

                                    The test program is running as an unprivileged user. As a result it cannot write into /etc/xdg to create Example/Settings.conf and you get the Access error.

                                    On my Kubuntu machine an unprivileged user opening QSettings::SystemScope actually does get a writable path, but it is under ~/.config/kdedefaults not /etc/xdg (where it would fail). This is likely an environmental difference (i.e. XDG_CONFIG_DIRS has been modified by KDE to include the writable path first).

                                    1 Reply Last reply
                                    0
                                    • JonBJ JonB

                                      @Bengt-0
                                      Firstly, please read through @ChrisW67's very thorough sample code in his last post.

                                      Going back to your original question/"bad" behaviour:

                                      I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.

                                      Along with my settings INI file, I want to store a log file at the same location.

                                      In a different section of my program, I use QSettings::fileName() to find the path to the log file.

                                      However, the file path from ::fileName is instead /etc/xdg/xdg-Lubuntu/myOrg, not /etc/xdg/myOrg.

                                      I do not get this. In particular I do not get your "I can see that my settings INI file is stored in /etc/xdg/myOrg/ as expected.". And I don't know how exactly this comes about for you, since you showed

                                      ~$ ls -ld /etc/xdg
                                      drwxr-xr-x 12 root root 4096 Oct 6 21:07 /etc/xdg
                                      

                                      Since /etc/xdg is writable only by root, how did you get /etc/xdg/myOrg/ and what are its permissions/who is it writable by?

                                      Here is the test code I used:

                                      #include <QCoreApplication>
                                      #include <QDebug>
                                      #include <QSettings>
                                      
                                      int main(int argc, char *argv[])
                                      {
                                          QCoreApplication a(argc, argv);
                                      
                                          QCoreApplication::setOrganizationName("Example");
                                          QCoreApplication::setOrganizationDomain("example.com");
                                          QCoreApplication::setApplicationName("Settings");
                                      
                                          QSettings userSettings(QSettings::UserScope, "Example", "Settings");
                                          qDebug() << userSettings.fileName();
                                          userSettings.setValue("abc", "def");
                                          userSettings.sync();
                                          qDebug() << userSettings.status();
                                      
                                          QSettings systemSettings(QSettings::SystemScope, "Example", "Settings");
                                          qDebug() << systemSettings.fileName();
                                          systemSettings.setValue("abc", "def");
                                          systemSettings.sync();
                                          qDebug() << systemSettings.status();
                                      
                                          return a.exec();
                                      }
                                      

                                      [I have to use a slightly different QSettings constructor from you since I am on Qt 5.12, but it's the same effect.] Running as me, not root (is that your case too?). And my output is:

                                      "/home/jon/.config/Example/Settings.conf"
                                      QSettings::NoError
                                      "/etc/xdg/xdg-ubuntu/Example/Settings.conf"
                                      QSettings::AccessError
                                      

                                      just as I would expect.

                                      B Offline
                                      B Offline
                                      Bengt 0
                                      wrote on last edited by
                                      #22

                                      @JonB

                                      Got it now.

                                      If I try to access read/write SystemScope prefs as root, the app looks in /etc/xdg/MYORG.
                                      If I try to access readonly SystemScope prefs as user, the app looks in /etc/xdg/xdg-Lubuntu/MYORG.

                                      Is this normal and expected?

                                      JonBJ 1 Reply Last reply
                                      0
                                      • B Bengt 0

                                        @JonB
                                        Jon,

                                        I sense some possible miscommunication here.

                                        First, the listing of directory content.
                                        I am using "ls-la" and not "ls -ld":

                                        $ ls -la /etc/xdg/
                                        total 76
                                        drwxr-xr-x  13 root root  4096 Oct  8 12:15 .
                                        drwxr-xr-x 130 root root 12288 Oct  7 08:32 ..
                                        -rw-r--r--   1 root root    86 Mar  5  2022 accept-languages.codes
                                        drwxr-xr-x   2 root root  4096 Oct  7 08:00 autostart
                                        drwxr-xr-x   2 root root  4096 Oct  8 11:53 Example
                                        -rw-r--r--   1 root root   153 Mar  5  2022 kshorturifilterrc
                                        drwxr-xr-x   2 root root  4096 Aug  9 13:50 libfm
                                        drwxr-xr-x   3 root root  4096 Aug  9 13:49 lxqt
                                        drwxr-xr-x   2 root root  4096 Aug  9 13:51 menus
                                        drwxr-xr-x   2 root root  4096 Oct  8 12:37 MYORG
                                        drwxr-xr-x   2 root root  4096 Aug  9 13:50 openbox
                                        drwxr-xr-x   2 root root  4096 Aug  9 13:47 systemd
                                        drwxr-xr-x   2 root root  4096 Aug  9 13:50 ui
                                        -rw-r--r--   1 root root   414 Mar 25  2022 user-dirs.conf
                                        -rw-r--r--   1 root root   418 Mar 25  2022 user-dirs.defaults
                                        drwxr-xr-x   9 root root  4096 Aug  9 13:51 xdg-Lubuntu
                                        drwxr-xr-x   2 root root  4096 Aug  9 13:51 Xwayland-session.d
                                        
                                        $ ls -la /etc/xdg/MYORG
                                        total 12
                                        drwxr-xr-x  2 root root 4096 Oct  8 12:37 .
                                        drwxr-xr-x 13 root root 4096 Oct  8 12:15 ..
                                        -rw-r--r--  1 root root  227 Oct  8 12:37 MYAPP.ini
                                        
                                        $ ls -la /etc/xdg/xdg-Lubuntu/
                                        total 48
                                        drwxr-xr-x  9 root root 4096 Aug  9 13:51 .
                                        drwxr-xr-x 13 root root 4096 Oct  8 12:15 ..
                                        drwxr-xr-x  2 root root 4096 Aug  9 13:51 autostart
                                        drwxr-xr-x  2 root root 4096 Aug  9 13:51 libfm
                                        drwxr-xr-x  2 root root 4096 Aug  9 13:51 lxqt
                                        -rw-r--r--  1 root root 8468 Nov 14  2021 mimeapps.list
                                        drwxr-xr-x  2 root root 4096 Aug  9 13:51 nm-tray
                                        drwxr-xr-x  2 root root 4096 Aug  9 13:51 openbox
                                        drwxr-xr-x  3 root root 4096 Aug  9 13:49 pcmanfm-qt
                                        drwxr-xr-x  2 root root 4096 Aug  9 13:51 qterminal.org
                                        
                                        
                                        

                                        Here you can see that MYORG resides in /etc/xdg, and MYAPP.ini is in /etc/xdg/MYORG. /etc/xdg/xdg-Lubuntu does not contain any of my files.

                                        Now to the sample code, and this is interesting. Thanks for supplying the sample code, both of you, you were quicker than me.

                                        The sample code from @ChrisW67 works correctly. I tried it and got the same result.
                                        However, your code (JonB) reproduces my problem if I try it, and you also write this in your post.

                                        "/home/jon/.config/Example/Settings.conf"
                                        QSettings::NoError
                                        "/etc/xdg/xdg-ubuntu/Example/Settings.conf"
                                        QSettings::AccessError
                                        

                                        You seem to think this is ok and expected, you need to explain why to me.

                                        I would expect qDebug() << systemSettings.fileName(); to give "/etc/xdg/Example/Settings.conf".

                                        There is something I do not understand here.

                                        BN

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by JonB
                                        #23

                                        @Bengt-0
                                        You show

                                        drwxr-xr-x 2 root root 4096 Oct 8 11:53 Example
                                        -rw-r--r-- 1 root root 227 Oct 8 12:37 MYAPP.ini

                                        Both of these are owned by root, and in directories only writable by root. I stated:

                                        Running as me, not root (is that your case too?)

                                        Are you running as root?? Else I'm not sure how you have permission to write to either of these?

                                        I would expect qDebug() << systemSettings.fileName(); to give "/etc/xdg/Example/Settings.conf"

                                        I would not, because /etc/xdg is not writable by me (user jon), so Qt (or XDG) is not going to pick that as a suitable location to save/write a config file.

                                        You need to be 100% explicit about:

                                        • Who you are running your application as?
                                        • Are you indeed interested in QSettings::SystemScope, not UserScope?

                                        [This was in answer to your earlier post, you may be beginning to clarify in your latest post.]

                                        B 1 Reply Last reply
                                        0
                                        • JonBJ JonB

                                          @Bengt-0
                                          You show

                                          drwxr-xr-x 2 root root 4096 Oct 8 11:53 Example
                                          -rw-r--r-- 1 root root 227 Oct 8 12:37 MYAPP.ini

                                          Both of these are owned by root, and in directories only writable by root. I stated:

                                          Running as me, not root (is that your case too?)

                                          Are you running as root?? Else I'm not sure how you have permission to write to either of these?

                                          I would expect qDebug() << systemSettings.fileName(); to give "/etc/xdg/Example/Settings.conf"

                                          I would not, because /etc/xdg is not writable by me (user jon), so Qt (or XDG) is not going to pick that as a suitable location to save/write a config file.

                                          You need to be 100% explicit about:

                                          • Who you are running your application as?
                                          • Are you indeed interested in QSettings::SystemScope, not UserScope?

                                          [This was in answer to your earlier post, you may be beginning to clarify in your latest post.]

                                          B Offline
                                          B Offline
                                          Bengt 0
                                          wrote on last edited by
                                          #24

                                          @JonB

                                          We have a difficulty with timing right now..:)

                                          What I am interested in:

                                          I want to WRITE the settings as root, System Scope.
                                          I want to READONLY the same SystemScope settings as user.

                                          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