Qt QSetting讀取配置 ini檔案

2021-10-24 06:59:32 字數 1365 閱讀 8730

----|開啟.ini配置檔案

qsettings settings(strconfigfile, qsettings::iniformat);

----|讀資料

settings.begingroup("basic"); //進入[basic]

settings.value("enable_english").tobool() //取值並轉bool型別

settings.endgroup(); //退出[basic]

settings.begingroup("database"); //進入[database]

tablelistfilename = settings.value("tablelistfile").tostring(); //取值並轉為string

int type = settings.value("type").toint(); //取值並轉int型別

settings.endgroup(); //退出[database]

//value第二引數是預設值,如果value不存在就使用預設引數

settings.begingroup("query");

m_nsingleexportmax = settings.value("singleexportmax",500).toint();

settings.endgroup();

----|寫資料 //寫資料不建議使用qsetting函式,會破壞配置檔案的注釋

settings.begingroup("server");

settings.setvalue("ip", "192.168.1.120");

settings.setvalue("port", 10001);

settings.endgroup();

[basic]

enable_english=false

enable_pie_plot=false

login_timeout_sec=300

measure_compare_display=false

[database]

tablelistfile=config/db.table.list.txt

type=0

[query]

singleexportmax=2000

singlepagesize=100

#database/type=mysql or sqlite

#type value 0 : sqlite 1 : mysql

python讀取配置 python讀取配置檔案

本機 python3.5 1.需要安裝configerparser py2是 configparser 2.編寫 執行前 coding utf8 import configparser conf configparser.configparser conf.read f python clstudy...

Thinkphp 配置 讀取配置

無論何種配置檔案,定義了配置檔案之後,都統一使用系統提供的c方法 可以借助config單詞來幫助記憶 來讀取已有的配置。用法 c 引數名稱 例如,讀取當前的url模式配置引數 model c url model 由於配置引數不區分大小寫,因此下面的寫法是等效的 model c url model 但...

Python中做介面自動化如何讀取配置ini檔案

使用python做介面自動化過程中,往往會使用配置檔案,方便後期維護。帶著大家熟悉一下configparser常用的方法使用 configparser 是用來讀取配置檔案的包。配置檔案的格式如下 中括號 內包含的為section。section 下面為類似於key value 的配置內容 例如 co...