Results 1 to 2 of 2

Thread: The question of writing configuration files

  1. #1
    Join Date
    Mar 2014
    Location
    china
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default The question of writing configuration files

    I writed some strings to a configuration file in Qt program, the configuration file named System.cfg.

    Before writing, the content of the configuration file looks like this:
    Qt Code:
    1. [Operate]
    2. Key="HallBrushCardGateIn,1514,1,A,T,T;
    3. HallBrushCardGateIn,1511,1,A,T,T;
    4. HallBrushCardGateIn,1515,1,A,T,T;
    5. HallBrushCardGateIn,1509,1,A,T,T;
    6. HallBrushCardGateIn,1510,1,A,T,T;
    7. HallBrushCardGateIn,1512,1,A,T,T;
    8. HallBrushCardSignIn,1514,1,A,T,T;
    9. HallBrushCardSignIn,1515,1,A,T,T;
    10. HallBrushCardSignIn,1509,1,1#3,F,T;
    11. HallBrushCardSignIn,1510,1,0#1#3#4,T,T;
    12. HallBrushCardSignIn,1512,1,0#1#3#4,T,T;
    13. IntoExamBrushCard,1514,1,A,T,T;
    14. IntoExamBrushCard,1515,1,A,T,T;
    15. IntoExamBrushCard,1511,1,A,T,T;
    16. IntoExamBrushCard,1512,1,1#3#4,F,T;
    17. ..............
    To copy to clipboard, switch view to plain text mode 
    After writing, it looks like this:
    Qt Code:
    1. [Operate]
    2. Key="HallBrushCardGateIn,1514,1,A,T,T;\r\n HallBrushCardGateIn,1511,1,A,T,T;\r\n HallBrushCardGateIn,1515,1,A,T,T;\r\n HallBrushCardGateIn,1509,1,A,T,T;\r\n HallBrushCardGateIn,1510,1,A,T,T;\r\n HallBrushCardGateIn,1512,1,A,T,T;\r\n HallBrushCardSignIn,1514,1,A,T,T;\r\n HallBrushCardSignIn,1515,1,A,T,T;\r\n HallBrushCardSignIn,1509,1,1#3,F,T;\r\n HallBrushCardSignIn,1510,1,0#1#3#4,T,T;\r\n HallBrushCardSignIn,1512,1,0#1#3#4,T,T;\r\n IntoExamBrushCard,1514,1,A,T,T;\r\n IntoExamBrushCard,1515,1,A,T,T;\r\n IntoExamBrushCard,1511,1,A,T,T;\r\n IntoExamBrushCard,1512,1,1#3#4,F,T;\r\n CustomerLevelOperate,1514,1,1#3,T,T;\r\n DepartmentOperateVIP,1511,1,1#2#3#4#7,F,T;\r\n DepartmentOperateGender,1511,1,1#2#3#4#7,F,T;\r\n DepartmentOperatePartition,1511,0,1#2#3#4#7,F,T;\r\n DepartmentOperateStatus,1511,1,1#2#3#4#7,F,T;\r\n OfficeEnabled,1511,1,1#2#3#4#7,F,F;\r\n OfficeDisabled,1511,1,1#2#3#4#7,F,F;\r\n ExamItemOperate,1514,1,A,T,T;\r\n
    To copy to clipboard, switch view to plain text mode 
    The content format was changed.

    can i keep original format after writing in Qt program?
    Can someone help me?

    Thanks!!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: The question of writing configuration files

    Why do you need to keep the original format? Configuration files are meant to be used by QSettings, and QSettings will write a string value on one line. Because your original file had CRLF and leading tabs or spaces in it, QSettings retained those and inserted the CRLF as \r\n when it wrote the line back out.

    If you don't like this behavior, then you'll have to write your own QSettings format (see QSettings::registerFormat()) that will write things out the way you like them.

Similar Threads

  1. Database vs Configuration files
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2013, 13:32
  2. Qt Configuration Question (SQL)
    By Blando in forum Installation and Deployment
    Replies: 1
    Last Post: 15th May 2010, 10:03
  3. Replies: 1
    Last Post: 27th August 2009, 06:41
  4. Configuration files
    By rbp in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2009, 07:47
  5. Configuration on txt files
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2008, 08:48

Tags for this Thread

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.