Results 1 to 5 of 5

Thread: QSettings

  1. #1
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSettings

    Hello,

    I have difficulty supplying arguments to QSettings::value()
    This is in the settings file:

    Qt Code:
    1. [domains]
    2. 1=dyndns
    3.  
    4. [dyndns]
    5. type=dyndns
    To copy to clipboard, switch view to plain text mode 

    Now if I call
    Qt Code:
    1. qDebug() << ini.value("dyndns/type").toString();
    To copy to clipboard, switch view to plain text mode 
    I get "dyndns"

    But if I call
    Qt Code:
    1. ini.beginGroup("domains");
    2. QStringList l = ini.allKeys();
    3. for (int i = 0; i < l.size(); i++)
    4. {
    5. QString Domain = ini.value(l.at(i)).toString(), S = QString("%1/type").arg(Domain), Type = ini.value(S).toString();
    6. qDebug() << Domain << S << Type;
    7. }
    To copy to clipboard, switch view to plain text mode 

    I don't get the Type string, it's empty, I get "dyndns" "dyndns/type" ""

    Thanks.
    Last edited by JeanC; 27th February 2011 at 14:24.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings

    Line #5 should read:
    Qt Code:
    1. QString Domain = ini.value(l.at(i)).toString(), Type = ini.value("type").toString();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings

    Thanks,
    I tried it but Type is still empty.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings

    Ouch, sorry I didn't look at the ini file. This is the correct code:
    Qt Code:
    1. ini.beginGroup("domains");
    2. QStringList groups;
    3. foreach(const QString &key, ini.childKeys()) groups << ini.value(key).toString();
    4. ini.endGroup();
    5. foreach(const QString &group, groups){
    6. QString S = QString("%1/type").arg(group), Type = ini.value(S).toString();
    7. qDebug() << group << S << Type;
    8. }
    To copy to clipboard, switch view to plain text mode 
    Line #7 can also be replaced with:
    Qt Code:
    1. ini.beginGroup(group);
    2. QString Type = ini.value("type").toString();
    3. ini.endGroup();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    JeanC (27th February 2011)

  6. #5
    Join Date
    Dec 2007
    Location
    Groningen Netherlands
    Posts
    182
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings

    Thanks this works, I already had a suspicion about forgetting endGroup().
    Nice code, I didn't know about the foreach() yet, I'm gonna study it.

Similar Threads

  1. Replies: 1
    Last Post: 14th January 2011, 11:57
  2. QSettings to/from xml
    By hubbobubbo in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2010, 12:04
  3. how to use Qsettings
    By elDua in forum Newbie
    Replies: 1
    Last Post: 5th August 2010, 21:22
  4. QSettings.
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2009, 19:14
  5. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 03: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.