QSettings::UserScope:用户环境,设置在当前用户的特定位置中。
QSettings::SystemScope:系统环境,设置在全局型,所有用户均可获得。 以下是对应QSettings::Format和QSettings::Scope存放的默认路径位置,其中*表示的是对应的程序名称:
Platform Format Scope Path
Windows NativeFormat UserScope HKEY_CURRENT_USERSoftware*
SystemScope HKEY_LOCAL_MACHINESoftware*
IniFormat UserScope %APPDATA%*.ini
SystemScope %COMMON_APPDATA%*.ini
Unix NativeFormat UserScope $HOME/.config/*.conf
SystemScope /etc/xdg/*.conf
IniFormat UserScope $HOME/.config/*.ini
SystemScope /etc/xdg/*.ini
Mac OS X NativeFormat UserScope $HOME/Library/Preferences/com.*.plist
SystemScope /Library/Preferences/com.*.plist
IniFormat UserScope $HOME/.config/*.ini
SystemScope /etc/xdg/*.ini
在读写时,路径名必须是"/"而不是"\"等。否则不能读写,注意。 以Windows XP平台为例,举俩个例子程序~ ■、读写注册表
//Format为QSettings::NativeFormat
QSettings settings("HKEY_CURRENT_USER\Software\Microsoft\Office",
QSettings::NativeFormat);
//设置键值信息
settings.setValue("11.0/Outlook/Security/DontTrustInstalledFiles", 0);
//获取键值信息
int value = settings.value("11.0/Outlook/Security/DontTrustInstalledFiles").toInt();
删除设置对应的是settings->remove( const QString & key ); ■、读取ini配置文件
先定义下software.ini文件的格式,比较简单: [bolg]
Name = "vic.MINg"
//Format为QSettings::IniFormat
QSettings *setIni=new QSettings ("software", QSettings::IniFormat);
//设置键值信息
setIni->beginGroup("bolg");
setIni->setValue("Name", "vic.MINg");
setIni->endGroup();
//获取键值信息
setIni->beginGroup("bolg");
QString resault = setIni->value("Name").toString();
setIni->endGroup();
qDebug()<<resault;