PDA

View Full Version : The question of writing configuration files



lzyinformation
26th May 2014, 14:33
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:


[Operate]
Key="HallBrushCardGateIn,1514,1,A,T,T;
HallBrushCardGateIn,1511,1,A,T,T;
HallBrushCardGateIn,1515,1,A,T,T;
HallBrushCardGateIn,1509,1,A,T,T;
HallBrushCardGateIn,1510,1,A,T,T;
HallBrushCardGateIn,1512,1,A,T,T;
HallBrushCardSignIn,1514,1,A,T,T;
HallBrushCardSignIn,1515,1,A,T,T;
HallBrushCardSignIn,1509,1,1#3,F,T;
HallBrushCardSignIn,1510,1,0#1#3#4,T,T;
HallBrushCardSignIn,1512,1,0#1#3#4,T,T;
IntoExamBrushCard,1514,1,A,T,T;
IntoExamBrushCard,1515,1,A,T,T;
IntoExamBrushCard,1511,1,A,T,T;
IntoExamBrushCard,1512,1,1#3#4,F,T;
..............

After writing, it looks like this:


[Operate]
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

The content format was changed.

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

Thanks!!

d_stranz
26th May 2014, 21:04
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.