版权声明:引用请注明出处 https://blog.csdn.net/quange_style/article/details/71261207
在嵌入式QT中,常常需要保存用户的操作习惯
ps:在开机重启时,需要显示重启以前的状态,这就需要将用到配置文件,将相关参数保存下来,也就是说保留配置文件。
考虑到系统调用等操作,可以将其分为读,写两个操作。
步骤1:
创建结构体struct,将需要用到保存的参数一条条归类好,对应一个个模块
PS:
typedef struct
{
MAINBUTTONSET qtMainButton;
DVRCONDUTINGSET qtDvrConductingSet;
CHANWINSET qtChanwinSet;
FILEMNGSET qtFileMngSet;
CONDUCTINGSET qtCondutingSet;
SYSSET QtSysSet;
PictureSet_S UserDefPicture;
OSDINFO OsdInfo;
int ResetEn;
}QTSET,*PQTSET;
步骤2:初始化结构体
QTSET qtparam;
qtparam.PQTSET=0;
...
步骤3:读取配置文件
ReadProfileFile(&qtparam,sizeof(qtparam));
int ReadProfileFile(char *fileName, unsigned int *actualReadSize)
{
FILE *hndlFile;
hndlFile = fopen(fileName, "rb");
if(hndlFile == NULL)
{
retVal = 0;
}
readDataSize = fread(curAddr, 1, chunkSize, hndlFile);
......
fclose(hndlFile);
}
步骤4:修改保存配置文件
WriteProfileFile(filename, &qtparam,sizeof(qtparam));
int WriteProfileFile(char *fileName, unsigned char *addr, unsigned int size)
{
FILE *hndlFile;
if(size==0)
return 0;
hndlFile = fopen(fileName,"wb");
writeDataSize = fwrite(fileName, 1, size, hndlFile);
.....
fclose(hndlFile);
}