Описание тега qsettings
QSettings
provides a very easy way to store, read and modify application settings in qt. Using this class is very simple.
The first thing to be done is creating an instance of QSettings
. It gets 2 arguments which are the application's name, and the developer's company or organization. These are needed to name the settings files (on Unix-like systems) or the register branches (on Windows):
QSettings mySettings("myCompany","myAppName");
It is also possible to pre-set those values to get rid of the necessity of passing them every time a QSettings
object is created. This can be done with QCoreApplication::setOrganizationName()
and QCoreApplication::setApplicationName()
.
After a QSettings
object is created, reading and writing settings is as easy as this:
//setting a value. The name should be QString, and the value can be a QVariant.
mySettings.setValue("valueName", "value");
//reading a value:
mySettings.value("vaueName");
The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.