In the Windows operating system, most of the configuration file information is written in the registry, or written in the *.ini file, for both of these operations have the corresponding Windows API functions, mentioned in the previous article, there is no more said ~
In Qt, a corresponding configuration file class qsetting is provided, using the Qsetting class to easily store user settings and application settings on disk.
Qsettings::format (Configuration Storage format) is divided into Nativeformat, Iniformat, Invalidformat. The main talk here is Nativeformat and Iniformat.
Qsettings::nativeformat: In Windows, using the system registry to store, in Mac OS x, using the system's cfpreferences mechanism to store (using the core Foundation Preference API) ; In other platforms, the settings are stored in a text file.
Qsettings::iniformat: Read/write *.ini format configuration file, Nativeformat extension in some operating systems is *.conf.
Qsettings::scope (Configuration Storage scope) is divided into Userscope, Systemscope.
Qsettings::userscope: User environment, set in a specific location for the current user.
Qsettings::systemscope: System environment, set in a global type, available to all users.
The following are the default path locations that correspond to Qsettings::format and Qsettings::scope, where * represents the corresponding program name:
Platform Format Scope Path
Windows Nativeformat Userscope hkey_current_user\software\*
Systemscope hkey_local_machine\software\*
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
When reading and writing, the path name must be "/" rather than "\ \" and so on. Otherwise, you cannot read or write, note.
Take the Windows XP platform, for example, to give two example programs ~
, read and write the registration form
Format is Qsettings::nativeformat
Qsettings settings ("Hkey_current_user\\software\\microsoft\\office",
Qsettings::nativeformat);
Setting key value Information
Settings.setvalue ("11.0/outlook/security/donttrustinstalledfiles", 0);
Get key value information
int value = Settings.value ("11.0/outlook/security/donttrustinstalledfiles"). ToInt ();
The corresponding value is bool,double,qstring,qstringlist, or the data type supported by other Qvariant, and also includes the registered user custom type.
The deletion settings correspond to Settings->remove (const QString & key);
, read the INI configuration file
The format of the next Software.ini file is defined first, which is relatively simple:
[Bolg]
Name = "Vic." MINg "
Format is Qsettings::iniformat
Qsettings *setini=new qsettings ("Software", Qsettings::iniformat);
Setting key value Information
Setini->begingroup ("Bolg");
Setini->setvalue ("Name", "Vic.") MINg ");
Setini->endgroup ();
Get key value information
Setini->begingroup ("Bolg");
QString Resault = Setini->value ("Name"). ToString ();
Setini->endgroup ();
Qdebug () <<resault;
The application of qsetting is not difficult, but it is very useful, some more detailed operation usage, can see the Help document!
You can refer to the example: $QTDIR \examples\tools\settingseditor
Http://cool.worm.blog.163.com/blog/static/643390062008426102655150/
QT configuration Information settings (qsettings use path under different platforms)