Results 1 to 6 of 6

Thread: structures to a file (read and write)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default Re: structures to a file (read and write)

    thanks for the reply ...just a follow up .. I have encountered the following

    from my practice I did the following

    Qt Code:
    1. typedef struct s_mystruct
    2. {
    3. int car;
    4. double wife;
    5. bool isActive;
    6. QHash <int,QString> map;
    7. }t_mystruct;
    8.  
    9. t_mystruct st;
    10.  
    11. QSettings settings("information.xfg",QSettings::IniFormat);
    12.  
    13. for (int i = 0; i <20;i++) //just to try
    14. {
    15. st.map.insert(i,QString("Driver No. %1").arg(i));
    16. }
    17.  
    18. settings.beginGroup("CarMap");
    19. settings.beginWriteArray("Car");
    20. QList<int> keys = st.map.keys();
    21. for (int i = 0; i < keys.count(); ++i) {
    22. settings.setArrayIndex(i);
    23. int xx = keys.at(i);
    24. settings.setValue("PlateNumber", keys.at(i));
    25. settings.setValue("Driver",st.map.value(keys.at(i)));
    26. }
    27. settings.endArray();
    28. settings.endGroup();
    To copy to clipboard, switch view to plain text mode 

    then, i got


    [CarMap]
    Car\1\Driver=Driver No. 0
    Car\1\PlateNumber=0
    Car\10\Driver=Driver No. 9
    Car\10\PlateNumber=9
    Car\11\Driver=Driver No. 10
    Car\11\PlateNumber=10
    Car\12\Driver=Driver No. 11
    Car\12\PlateNumber=11
    Car\13\Driver=Driver No. 12
    Car\13\PlateNumber=12
    Car\14\Driver=Driver No. 13
    Car\14\PlateNumber=13
    Car\15\Driver=Driver No. 14
    Car\15\PlateNumber=14
    Car\16\Driver=Driver No. 15
    Car\16\PlateNumber=15
    Car\17\Driver=Driver No. 16
    Car\17\PlateNumber=16
    Car\18\Driver=Driver No. 17
    Car\18\PlateNumber=17
    Car\19\Driver=Driver No. 18
    Car\19\PlateNumber=18
    Car\2\Driver=Driver No. 1
    Car\2\PlateNumber=1
    Car\20\Driver=Driver No. 19
    Car\20\PlateNumber=19
    Car\3\Driver=Driver No. 2
    Car\3\PlateNumber=2
    Car\4\Driver=Driver No. 3
    Car\4\PlateNumber=3
    Car\5\Driver=Driver No. 4
    Car\5\PlateNumber=4
    Car\6\Driver=Driver No. 5
    Car\6\PlateNumber=5
    Car\7\Driver=Driver No. 6
    Car\7\PlateNumber=6
    Car\8\Driver=Driver No. 7
    Car\8\PlateNumber=7
    Car\9\Driver=Driver No. 8
    Car\9\PlateNumber=8
    Car\size=20
    How can I changed the sorting style of the ouput text , I want that all cars should be in order, not like above?
    ie Car\10\... should follow Car\9\...

    baray98

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

    Default Re: structures to a file (read and write)

    What for? The order doesn't really matter, it's just a config file... If you want to change the order, prepend all single digit section names with "0". Of course you won't be able to use automatic section naming through array support.

  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default Re: structures to a file (read and write)

    So Ill take it as a NO ...can't do it

    and for your question of why......the answer is below

    I may need to edit this manually in the future and i dont want to be confused of how many cars do i have ?

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

    Default Re: structures to a file (read and write)

    Quote Originally Posted by baray98 View Post
    I may need to edit this manually in the future and i dont want to be confused of how many cars do i have ?
    Qt Code:
    1. Car\size=20
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How can I Read Write Excel File
    By xingshaoyong in forum Qt Programming
    Replies: 6
    Last Post: 13th July 2011, 20:16
  2. How to open a file in Read Write mode
    By merry in forum Qt Programming
    Replies: 13
    Last Post: 16th November 2007, 14:40
  3. Read \Write Excel File using Qt
    By xingshaoyong in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 22:07
  4. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48
  5. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 14:12

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.