Results 1 to 3 of 3

Thread: QSettings problem in windows

  1. #1
    Join Date
    Mar 2011
    Posts
    24
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QSettings problem in windows

    I have a program in windows platform ...........

    I have just made up a registry like this....

    chow
    kurra
    Settings

    in the Settings key i have some string values like say "showDialogOnPrinting" which data is not set...

    Now in my program i set my organisationName to chow

    and my application name to kurra

    and Code like this....

    Qt Code:
    1. QSettings settings;
    2. settings.beginGroup("Settings");
    3. bool shDialog = settings.value("showDialogOnPrinting",false);
    4. checkboxShDialog->setChecked(shDialog);
    To copy to clipboard, switch view to plain text mode 

    here the settings.value("showDialogOnPrinting",false); is supposed to set false if there is no value(According to docs the false in this case is the default/fallback value).

    But that didnt set false in the registry....and the code was successfully executed..

    when i change the value to true in the registry, it works good,it fetches the true and checks the box....

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSettings problem in windows

    But that didnt set false in the registry....and the code was successfully executed..
    It will not set the value in registry, it will return false if there is no such key in your settings, or it's value is not convertible to bool. So the variable shDialog will be true/false depending on the value in settings. Reading values from settings will not change the registry.
    In order to set a value in registry you need to use
    Qt Code:
    1. bool b = ...;
    2. ...
    3. QSettings settings;
    4. settings.beginGroup("Settings");
    5. settings.setValue("showDialogOnPrinting",b);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings problem in windows

    HI,

    try using QVariant::toBool() when you reading value.

    Qt Code:
    1. QSettings settings;
    2. settings.beginGroup("Settings");
    3. bool shDialog = settings.value("showDialogOnPrinting",false).toBool();
    4. checkboxShDialog->setChecked(shDialog);
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. QSettings problem on windows 7
    By ivareske in forum Qt Programming
    Replies: 17
    Last Post: 13th July 2012, 06:46
  2. QSettings in Windows
    By ManuMies in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2010, 10:31
  3. QSettings and Windows 7 64bit
    By JohnToddSr in forum Newbie
    Replies: 4
    Last Post: 12th May 2010, 02:01
  4. QSettings problem!
    By 0xl33t in forum Newbie
    Replies: 5
    Last Post: 28th July 2009, 08:15
  5. Replies: 1
    Last Post: 19th September 2008, 15:43

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
  •  
Qt is a trademark of The Qt Company.