Results 1 to 8 of 8

Thread: Read .ini files

  1. #1
    Join Date
    Oct 2009
    Posts
    70

    Default Read .ini files

    Hi...

    Is there with Qt something to read easily text file with Windows .ini style ?!?

    Like this:

    Qt Code:
    1. [GROUP 1]
    2.  
    3. key1 = value1
    4. key2 = value2
    5.  
    6. [GROUP 2]
    7.  
    8. key1 = value1
    9. ....
    To copy to clipboard, switch view to plain text mode 


    Thanks

  2. #2
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Read .ini files

    Hi,

    You can use QSettings :
    QSettings::QSettings ( const QString & fileName, Format format, QObject * parent = 0 )

    Fred.

  3. #3
    Join Date
    Oct 2009
    Posts
    37
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Read .ini files

    Please not that QSettings only properly reads INI files that were also created with QSettings. You might be lucky to read other INI files too, but it is not guaranteed.
    Disclaimer: Although I work on Qt for Nokia, anything I post here is personal

  4. #4
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Read .ini files

    Ok...but If I want to parse with Qt an existing INI file like this:

    Qt Code:
    1. [TOP_LEFT]
    2. [ELEMENT1]
    3. comment = Name
    4. tag = Cliente_Name
    5. sequence = 1
    6. Modality = all
    7. [ELEMENT2]
    8. comment = Birth_Date
    9. tag = Client_Birth_Date
    10. sequence = 2
    11. Modality = all
    12. [TOP_CENTER]
    13. [ELEMENT 1]
    14. comment = example
    15. tag = example
    16. sequence = 1
    17. Modality = all
    18. [ELEMENT 2]
    19. comment = example2
    20. tag = example2
    21. sequence = 2
    22. Modality = all
    23. [TOP]
    24. value = prove
    To copy to clipboard, switch view to plain text mode 

    I've try with QSettings and childGroups() but it doesn't works...

    Which is the better way to do this?

    Thanks

  5. #5
    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: Read .ini files

    As far as I know this is not a proper "ini" file. For the above mentioned file I'd use regexps.
    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.


  6. #6
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Read .ini files

    Sorry...but with RegExp how can you pass the text file?!

  7. #7
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read .ini files

    If you have to use this format of ini file, why not change it to XML file?

  8. #8
    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: Read .ini files

    Quote Originally Posted by paolom View Post
    Sorry...but with RegExp how can you pass the text file?!
    You parse it line by line and decide what to do with the result afterwards. For instance if you know the line is like "\[([A-Za-z0-9_]+)\]" then you know it is a (sub)group so you can create a group node in your final structure. If the line is like "([A-Za-z0-9_]+) = (.*)" then you know it is an item and you can create an item node in your final structure.
    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.


Similar Threads

  1. read ascii files with different column counts
    By pospiech in forum Qt Programming
    Replies: 5
    Last Post: 6th November 2009, 13:42
  2. QT read files
    By Majdi in forum Newbie
    Replies: 3
    Last Post: 21st January 2009, 10:17
  3. How can I read Binary files with Qt
    By geo_saleh in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2007, 11:37
  4. read files and save the,
    By kernel_panic in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2007, 07:31
  5. Read files PDF
    By henriquez0 in forum Qt Programming
    Replies: 3
    Last Post: 31st December 2006, 01:20

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.