The QSettings class manages the registry or configuration files

It is very easy to use the QSettings class to read the configuration information data of the entire system in Qt development .

Under Windows :

On the windows platform, QSettings provides the functions of reading and writing ini files and registry.

There are two types of QSettings::Format :

QSettings::NativeFormat can read and write windows registry on windows platform .

QSettings::IniFormat can read and write configuration files in ini format

The effects of these two Formats are the same under the Unix/X11 platform (think about it, too, Linux has no registry).

1. Read and write registry

    //FormatQSettings::NativeFormat

    QSettings*settings=newQSettings("HKEY_CURRENT_USER\\",QSettings::NativeFormat);

    // Write HKEY_CURRENT_USER/regedit, set the test value to red

    settings->setValue("regedit","red");

    // Read HKEY_CURRENT_USER/regedit, the default value is ddd

    QStringvalue=settings->value("regedit").toString();

    qDebug()<<value;

// Delete settings correspond to settings->remove( const QString & key )

2. Read the ini configuration file

    QStringfileName="./temp.ini";

QSettings*settings=newQSettings(fileName,QSettings::IniFormat);

settings->setValue("Alpha/Beta/Beta",68);

ini file format is as follows :

[Alpha]

Beta\Beta=68

 

Under Linux :

QSettingssettings=QSettings("/home/app.ini",QSettings::IniFormat);

Similar to managing configuration files under Windows , it is for reference only.

Guess you like

Origin blog.csdn.net/cliffordl/article/details/38702075