Results 1 to 5 of 5

Thread: How to set the scope of QSettings to be application based.

  1. #1
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default How to set the scope of QSettings to be application based.

    Hi all,

    I am using QSettings and have seen that one could set the applicationName and the organizationName for a QApplication, so that QSettings can be used as:
    Qt Code:
    1. QSettings settings;
    To copy to clipboard, switch view to plain text mode 
    and the setting will reside into the already set applicationName and organizationName.

    My question here: is there a possibility to achieve something similar also with the Scope of the QSettings.
    If i would just do QSettings settings; the Scope would be QSettings:UserScope and I need QSettings:SystemScope.

    One solution would be to use this constructor:
    Qt Code:
    1. QSettings settings(QSettings::SystemScope, QApplication::organizationName());
    To copy to clipboard, switch view to plain text mode 
    , but this involves more coding.

    Is there any other better way to achieve this?

    Thanks in advance,
    Wladek
    One second is long, everything longer than two seconds is definitely too long.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to set the scope of QSettings to be application based.

    See the static function QSettings::setPath().

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to set the scope of QSettings to be application based.

    Quote Originally Posted by Lykurg View Post
    See the static function QSettings::setPath().
    Ok, after a quick control look inside the documentation: Forget about that solution, I thought you can just swap the path, but it's not that easy.

    So for avoiding typing all that parameters, you can define a global function returning a proper settings object. (Or define a macro.)

  4. #4
    Join Date
    May 2010
    Posts
    61
    Thanks
    2
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to set the scope of QSettings to be application based.

    Hey Lykurg,

    Thanks for your reply. I did try to define a macro like:
    Qt Code:
    1. #define Settings QSettings(QSettings::SystemScope, QApplication::organizationName(), QApplication::applicationName());
    To copy to clipboard, switch view to plain text mode 
    But then when I would want to use it like:
    Qt Code:
    1. QSettings settings = Settings;
    To copy to clipboard, switch view to plain text mode 
    I would get the error:
    QSettings::QSettings(const QSettings&)' is private
    After checking with the QSettings source code i've seen that the copy constructor was disabled
    Qt Code:
    1. Q_DISABLE_COPY(QSettings)
    To copy to clipboard, switch view to plain text mode 

    So, as a solution I defined my own custom class, SystemSettings which inherits QSettings, and in it's constructor just calls the proper QSettings's constructor.
    Qt Code:
    1. class SystemSettings : public QSettings
    2. {
    3. public:
    4. SystemSettings()
    5. :QSettings(QSettings::SystemScope, QApplication::organizationName(), QApplication::applicationName()){};
    6. };
    To copy to clipboard, switch view to plain text mode 

    And, to be in the same side Qt is, i am also disabling my copy constructor:
    Qt Code:
    1. private:
    2. Q_DISABLE_COPY(SystemSettings);
    To copy to clipboard, switch view to plain text mode 

    Would you suggest different?

    Thanks,
    Wladek

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to set the scope of QSettings to be application based.

    Yeah, great, I'm a fan of subclassing Haven't thought of that before, and that's the most elegant solution!

Similar Threads

  1. QCA based application deployment problem
    By npclaudiu in forum Installation and Deployment
    Replies: 1
    Last Post: 14th May 2010, 10:10
  2. Replies: 0
    Last Post: 30th April 2010, 07:36
  3. How to run cosol based application in Qt creator
    By phillip_Qt in forum Qt Tools
    Replies: 1
    Last Post: 5th March 2010, 13:38
  4. Deploying Qt 4.4 based Mac application
    By Ian_001 in forum Installation and Deployment
    Replies: 0
    Last Post: 31st October 2008, 15:13
  5. QSettings setPath Scope
    By philwinder in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2008, 21:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.