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. Configure QSettings ((QSettings::Format and QSettings::Scope )
Forum Updated to NodeBB v4.3 + New Features

Configure QSettings ((QSettings::Format and QSettings::Scope )

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 7 Posters 1.4k Views 4 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.
  • jsulmJ jsulm

    @hbatalha said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

    QCoreApplication::setOrganizationName("MySoft");
    QCoreApplication::setOrganizationDomain("mysoft.com");
    QCoreApplication::setApplicationName("Star Runner");

    Where exactly in your code do you execute this?

    H Offline
    H Offline
    hbatalha
    wrote on last edited by hbatalha
    #3

    @jsulm said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

    Where exactly in your code do you execute this?

    in the main.cpp

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QCoreApplication::setOrganizationName("MySoft");
        QCoreApplication::setOrganizationDomain("mysoft.com");
        QCoreApplication::setApplicationName("Star Runner");
    
    ...
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #4

      Just subclass QSettings

      class MySettings : public QSettings{
          Q_OBJECT
          Q_DISABLE_COPY(MySettings)
      public:
          explicit MySettings(QObject *parent = nullptr)
              : QSettings(QSettings::IniFormat, QSettings::UserScope, 
      #ifdef Q_OS_DARWIN
                  QStringLiteral("mysoft.com")
      #else
                  QStringLiteral("MySoft")
      #endif
                  , QStringLiteral("Star Runner"), parent)
          {}
      };
      

      now use MySettings settings wherever you'd have used QSettings settings

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      kshegunovK 1 Reply Last reply
      3
      • VRoninV VRonin

        Just subclass QSettings

        class MySettings : public QSettings{
            Q_OBJECT
            Q_DISABLE_COPY(MySettings)
        public:
            explicit MySettings(QObject *parent = nullptr)
                : QSettings(QSettings::IniFormat, QSettings::UserScope, 
        #ifdef Q_OS_DARWIN
                    QStringLiteral("mysoft.com")
        #else
                    QStringLiteral("MySoft")
        #endif
                    , QStringLiteral("Star Runner"), parent)
            {}
        };
        

        now use MySettings settings wherever you'd have used QSettings settings

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #5

        @VRonin said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

        Just subclass QSettings

        Ugh!
        Can't we have something like this instead?*

        QSettings mySettings()
        {
            return QSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(...));
        }
        

        *c++17 and later

        Use directly on initialization:

        QSettings settings = mySettings();
        

        Read and abide by the Qt Code of Conduct

        J.HilkJ 1 Reply Last reply
        2
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #6

          @kshegunov said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

          Can't we have something like this instead?*

          Potato/Potatoe

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          kshegunovK 1 Reply Last reply
          0
          • VRoninV VRonin

            @kshegunov said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

            Can't we have something like this instead?*

            Potato/Potatoe

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #7

            @VRonin said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

            Potato/Potatoe

            The point is to avoid type proliferation, I know you know that's a thing. Why derive anything if you don't have to; you're not changing any behavior here!

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • kshegunovK kshegunov

              @VRonin said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

              Just subclass QSettings

              Ugh!
              Can't we have something like this instead?*

              QSettings mySettings()
              {
                  return QSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral(...));
              }
              

              *c++17 and later

              Use directly on initialization:

              QSettings settings = mySettings();
              
              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #8

              @kshegunov don't you still need a class for this, or do you advocate a global free floating function here?


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              kshegunovK 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @kshegunov don't you still need a class for this, or do you advocate a global free floating function here?

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #9

                @J-Hilk said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

                @kshegunov don't you still need a class for this, or do you advocate a global free floating function here?

                A normal C-like function, inline-d ideally. Why would you make a class for this?

                Read and abide by the Qt Code of Conduct

                SGaistS 1 Reply Last reply
                1
                • kshegunovK kshegunov

                  @J-Hilk said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

                  @kshegunov don't you still need a class for this, or do you advocate a global free floating function here?

                  A normal C-like function, inline-d ideally. Why would you make a class for this?

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by SGaist
                  #10

                  @kshegunov you can't as QSettings is a QObject.

                  It does work with C++17, see @kshegunov answer below.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  kshegunovK 1 Reply Last reply
                  0
                  • Chris KawaC Online
                    Chris KawaC Online
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @hbatalha QSettings has static setDefaultFormat that you can call along those other set* functions, so the only part missing is the default scope, but it's not so bad I think?

                    QSettings settings(QSettings::SystemScope);
                    

                    It does feel like it would be kinda completing the API nicely if there was also something like static QSettings::setDefaultScope(QSettings::Scope). You could file a feature request on bugreports.qt.io if that's something you'd like to see in future versions.

                    H 1 Reply Last reply
                    3
                    • SGaistS SGaist

                      @kshegunov you can't as QSettings is a QObject.

                      It does work with C++17, see @kshegunov answer below.

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #12

                      @SGaist said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

                      @kshegunov you can't as QSettings is a QObject.

                      Au contraire mon ami! Excuse the bad friench, but the point is C++17 mandates RVO, so this compiles and runs correctly with g++. You don't make no copies here.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        The French part is completely correct :-)
                        I missed the C++17 bits. My bad !

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        kshegunovK 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          The French part is completely correct :-)
                          I missed the C++17 bits. My bad !

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by
                          #14

                          @SGaist said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

                          The French part is completely correct :-)

                          Good that my initial (and rather inexcusable) error was caught on time ;)

                          Read and abide by the Qt Code of Conduct

                          1 Reply Last reply
                          1
                          • Chris KawaC Chris Kawa

                            @hbatalha QSettings has static setDefaultFormat that you can call along those other set* functions, so the only part missing is the default scope, but it's not so bad I think?

                            QSettings settings(QSettings::SystemScope);
                            

                            It does feel like it would be kinda completing the API nicely if there was also something like static QSettings::setDefaultScope(QSettings::Scope). You could file a feature request on bugreports.qt.io if that's something you'd like to see in future versions.

                            H Offline
                            H Offline
                            hbatalha
                            wrote on last edited by
                            #15

                            @Chris-Kawa said in Configure QSettings ((QSettings::Format and QSettings::Scope ):

                            QSettings has static setDefaultFormat that you can call along those other set* functions, so the only part missing is the default scope, but it's not so bad I think?

                            That's a good idea, I read it in the doc but misunderstood its role. I will try this approach and @kshegunov's answer and get back to you.

                            1 Reply Last reply
                            1

                            • Login

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