Results 1 to 5 of 5

Thread: Problems with QSettings

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problems with QSettings

    Hi,
    I would load some settings from an ini file.
    Some settings are QColors so in my ini file I have a color section with many points so:
    Qt Code:
    1. [colors]
    2. background=
    3. waveform=
    4. timeline=
    5. markers=
    6. selection=
    To copy to clipboard, switch view to plain text mode 

    I would set some default values living empty the color fields in the ini file so I would that Qt load the default values so:

    Qt Code:
    1. QColor defColor = Qt::white; //default value
    2. QVariant colVariant = defColor; //convert in QVariant
    3. m_bgColor = settings.value( "background", colVariant ).value<QColor>(); // I would Qt::white as default value
    To copy to clipboard, switch view to plain text mode 

    but debuggind it says that m_bgColor is invalid and doesn't has the desired value.

    Where I'm wrong?

    Best
    Franco Amato

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems with QSettings

    In your ini-file background equals empty string, wich is invalid

  3. #3
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with QSettings

    Quote Originally Posted by borisbn View Post
    In your ini-file background equals empty string, wich is invalid
    Like this guy says, if there is a setting in the ini file it will mean there is a value even if there is not. If it uses a default value, like you say White. The entry will simply be not there. So remove the background= from the ini file and it will return white

    Always remember, default values will not be listed.
    entries listed have values even if empty

  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with QSettings

    Quote Originally Posted by ComaWhite View Post
    Like this guy says, if there is a setting in the ini file it will mean there is a value even if there is not. If it uses a default value, like you say White. The entry will simply be not there. So remove the background= from the ini file and it will return white

    Always remember, default values will not be listed.
    entries listed have values even if empty
    How can I set a default value in the ini file for a QColor? For example I would have white as default in the ini file and
    If the user would change it I'll update the value
    Franco Amato

  5. #5
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Problems with QSettings

    Well, like I said. If the user modified it, the entry will be in the ini, if not it won't be there.

Similar Threads

  1. Value from QSettings
    By wirasto in forum Newbie
    Replies: 7
    Last Post: 14th January 2010, 18:52
  2. QSettings.
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2009, 19:14
  3. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 03:21
  4. Qsettings
    By jrideout in forum Qt Programming
    Replies: 11
    Last Post: 29th June 2006, 19:21
  5. QSettings
    By incapacitant in forum Newbie
    Replies: 13
    Last Post: 25th May 2006, 11:08

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.