Results 1 to 4 of 4

Thread: QSettings

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QSettings

    Hi,

    If you use a default constructor for QSettings, it automatically gets the values of:

    Qt Code:
    1. QCoreApplication::setOrganizationName("MySoft");
    2. QCoreApplication::setOrganizationDomain("mysoft.com");
    3. QCoreApplication::setApplicationName("Star Runner");
    To copy to clipboard, switch view to plain text mode 

    That's all fine, but how do you then go about changing for example:

    Qt Code:
    1. QSettings::format()
    To copy to clipboard, switch view to plain text mode 

    This only returns the format used, but if I don't specify it in the default constructor because I want the program to automatically get the values of my organisation and application names, then there's no way of specifying the format after?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QSettings

    Quote Originally Posted by Qt Docs
    Use setDefaultFormat() before calling this constructor to change the default format used by this constructor.

    That's it. There no way to change once the QSettings object is created.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QSettings

    Dang, thanks anyway.

    A feature for future Qt versions? Wink wink... nudge nudge .

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSettings

    Create a wrapper class for QSettings (ie. one that uses a QSettings instance created on the fly) and use this wrapper class instead of QSettings itself. I think I posted such code here a month or so ago. You can customize that code to change the format on the fly if you wish by providing the format as an argument to the setValue() and value() methods. Each time the setValue() or value() method is called, the QSettings variable is created using the format and other constructor arguments (which could be member variables of the wrapper class or retrieved from qApp()), and that temporary QSettings instance is used to read or write the desired setting.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QSettings - how to use?
    By almalino in forum Qt Programming
    Replies: 10
    Last Post: 22nd September 2017, 05:17
  2. QSettings
    By JeanC in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2011, 16:52
  3. Replies: 1
    Last Post: 14th January 2011, 12:57
  4. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 04:21
  5. Qsettings
    By jrideout in forum Qt Programming
    Replies: 11
    Last Post: 29th June 2006, 20:21

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.