开发者

How to implement the key-value file operations in Qt

开发者 https://www.devze.com 2023-02-07 01:45 出处:网络
I want store my configuration data as like \"key\"-\"value\". Lets say key=开发者_开发百科IP then value=\"192.136.10.11\". So I have several such data to store in a file. I know the file seek, cursor

I want store my configuration data as like "key"-"value". Lets say key=开发者_开发百科IP then value="192.136.10.11". So I have several such data to store in a file. I know the file seek, cursor movement and data read/write is very boring things. So I want to know is there anything in Qt like I will open a file. Then store a pair like - putPair("IP","192.136.10.11");. For retreive data it could be like something getValue("IP"); and it should return me the value 192.136.10.11. I found this type of functionality in android.

Is there any such functionality in Qt?


For preferences like data, QSettings may do what you want.


You instantiate a QSettings class with QSettings::IniFormat to store key-value pair in an .ini file.

m_pApplicationSettings = new QSettings(m_strDependenciesDirPath+"\iConConfig.ini", QSettings::IniFormat, this);

The values are stored as QVariants, So the values can be stored and accessed as below,

m_pApplicationSettings->setValue("Temp Dir Path", QDir::tempPath()+"\iCon"); m_pApplicationSettings->value("Temp Dir Path",QDir::tempPath()+"\iCon").toString();


Sure. the QSettings class implements this functionality. You can use it to access a platforms standard INI file for your application or open your own file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号