Results 1 to 9 of 9

Thread: How to use QSettings to read INI file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QSettings to read INI file

    try this example:
    Qt Code:
    1. QSettings settings("test.ini", QSettings::IniFormat);
    2. settings.beginGroup("players");
    3. const QStringList childKeys = settings.childKeys();
    4. foreach (const QString &childKey, childKeys)
    5. qDebug() << settings.value(childKey);
    6. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. #2
    Join Date
    Oct 2009
    Posts
    4
    Thanks
    1

    Default Re: How to use QSettings to read INI file

    ok, i have ini file like:
    [user]
    0/name=lukasz
    0/wins=3
    0/loses=3
    1/name=pawel
    1/wins=1
    1/loses=5
    2/name=anna
    2/wins=1
    2/loses=5

    and my code is:
    Qt Code:
    1. settings = new QSettings("config.ini",QSettings::IniFormat);
    2. settings->beginGroup("user");
    3. QStringList player_number = settings->childGroups(); // returns 0, 1, 2 - OK !
    4. const QStringList childKeys = settings->childKeys(); // should return name, wins, ... right ?
    5. foreach(const QString &childKey, childKeys)
    6. {
    7. ui->choosePlayerBox->addItem(settings->value(childKey).toString()); // should add lukasz, 3, 3, pawel...., but it doesn`t work
    8.  
    9. }
    10. settings->endGroup();
    To copy to clipboard, switch view to plain text mode 

    Any ideas ?

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to use QSettings to read INI file

    you code will not work, because "0/name" it's a key, not a group.
    I suggest you to review format on your ini-file or use xml instead.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. The following user says thank you to spirit for this useful post:

    candyshop (16th November 2009)

  5. #4
    Join Date
    May 2010
    Location
    Bangalore, India.
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to use QSettings to read INI file

    Hi
    my .ini file is

    [System.Setting]
    auto_check_update=false
    auto_check_mode=weekly

    & the code to read is
    QString strKey("System.Setting/");
    QSettings * settings = 0;
    settings = new QSettings( file_path, QSettings::IniFormat );
    QString strMode = settings->value( strKey + "auto_check_mode", "r").toString();

    no problem with the code compiling & running. when i try to print strMode program is unexpectedly finising.. this is happening with QString, Date (Derived data types). but fine with basic data types like int, float, bool...
    using printf to print the values. qDebug is not working in this project. what could be the problem?

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

    Default Re: How to use QSettings to read INI file

    Does your derived data type(Date) support QVariant ?
    QSettings use QVariant to work.

Similar Threads

  1. Replies: 5
    Last Post: 27th May 2009, 12:49
  2. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  3. QFile can't read a file
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2009, 20:24
  4. [Java] read and write a file
    By mickey in forum General Programming
    Replies: 3
    Last Post: 22nd June 2008, 10:43
  5. Using QSettings to read pre-made INI file..
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 05:36

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.