需要#include
只舉幾個簡單的例子:
1、用qsettings寫登錄檔
1. qsettings *reg = new qsettings("hkey_current_user//software//yinhaifan",
2. qsettings::nativeformat);
3. reg->setvalue("registered",true);
4. delete reg;
qsettings *reg = new qsettings("hkey_current_user//software//yinhaifan", qsettings::nativeformat); reg->setvalue("registered",true); delete reg;
當然reg->setvalue還可以寫入字串,整型之類的資料。
比如reg->setvalue("registered","yes");
2、用qstring讀登錄檔
1. qsettings *reg = new qsettings("hkey_current_user//software//yinhaifan",
2. qsettings::nativeformat);
3. if (reg->value("registered",false).tobool())
4.
7. delete reg;
qsettings *reg = new qsettings("hkey_current_user//software//yinhaifan", qsettings::nativeformat); if (reg->value("registered",false).tobool()) delete reg;
還可以toint(),tostring()等。
3、用qsettings寫ini檔案:
1. qsettings *configini = new qsettings("d://a.ini",qsettings::iniformat,0);
2. configini->setvalue("/config/node1",ui->lineedit->text());
3. delete configini;
qsettings *configini = new qsettings("d://a.ini",qsettings::iniformat,0); configini->setvalue("/config/node1",ui->lineedit->text()); delete configini;
4、用qsettings讀ini檔案:
1. qsettings *configini = new qsettings("d://a.ini",qsettings::iniformat,0);
2. ui->lineedit_2->settext(configini->value("/config/node1","20").tostring());
3. delete configini;
qsettings *configini = new qsettings("d://a.ini",qsettings::iniformat,0); ui->lineedit_2->settext(configini->value("/config/node1","20").tostring()); delete configini;
這幾段**都是在qt creator裡面寫的,所以用ui->lineedit*->text()和ui->lineedit*->settext()做輸入和輸出了。
在文件中的qsettings class reference部分講的很清楚
檔案讀寫和登錄檔讀寫
檔案讀寫和登錄檔讀寫 新增如下選單專案 響應 一 檔案讀寫 void cfileview onfilewrite void cfileview onfileread 二 登錄檔讀寫 按鈕響應 void cfileview onregwrite void cfileview onregread 三 初...
MFC學習筆記 讀寫配置檔案 ini 和登錄檔
配置檔案中經常用到ini檔案,在vc中其函式分別為 寫入.ini檔案 讀取.ini檔案 讀取整形值 例子 寫入 cstring strname,strtemp int nage strname jacky nage 13 writeprivateprofilestring student name ...
QSettings寫登錄檔和INI檔案 開機自啟動
qsettings通過寫登錄檔和ini檔案提供了持久的跨平台應用程式的配置。一 讀寫登錄檔 1 通過指定公司名稱 產品名稱來構造qsettings物件 qsettings settings new qsettings jtv zhangzc settings setvalue size qsize ...