Results 1 to 9 of 9

Thread: read ini file content and save into array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: read ini file content and save into array

    Your syntax is all wrong. The first field in each entry is the index, the second the name of the value, and (you are completely missing this) the value itself comes after an equal sign. You are also missing the size attribute.

    This defines a 6-element array called StageNum, where each element has a value called "cy1" (test.ini):
    Qt Code:
    1. [Config]
    2. Number1=156
    3. Number2=4
    4.  
    5. [StageNum]
    6. size = 6
    7. 0/cy1 = 7
    8. 1/cy1 = 2
    9. 2/cy1 = 5
    10. 3/cy1 = 2
    11. 4/cy1 = 3
    12. 5/cy1 = 0
    To copy to clipboard, switch view to plain text mode 
    and this will read it:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QSettings>
    3. #include <QDebug>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication app(argc, argv);
    9.  
    10. QSettings m4Settings("test.ini", QSettings::IniFormat);
    11.  
    12. int arySize = m4Settings.beginReadArray("StageNum");
    13. qDebug() << "arySize =" << arySize;
    14. for (int vL = 0; vL < arySize; vL ++)
    15. {
    16. m4Settings.setArrayIndex(vL);
    17. qDebug()
    18. << "index =" << vL
    19. << "cy1 =" << m4Settings.value("cy1","0").toInt();
    20. }
    21. m4Settings.endArray();
    22.  
    23. return app.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to ChrisW67 for this useful post:

    cooper (13th March 2011)

Similar Threads

  1. read a .txt file and store it in a double array
    By fatecasino in forum Newbie
    Replies: 5
    Last Post: 3rd December 2010, 20:13
  2. QDomDocument can't read the file content
    By baluk in forum Newbie
    Replies: 21
    Last Post: 24th September 2010, 13:43
  3. read from file into array
    By obad in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2010, 08:26
  4. Save content of widget to pixmap
    By vql in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2008, 22:26
  5. how to copy QString content into array
    By eric in forum Qt Programming
    Replies: 12
    Last Post: 14th November 2007, 23:13

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.