介绍
官方帮助文档:QSettings
一套完整的配置文件读写机制,多平台支持,支持ini文件读写、win下注册表读写等操作。同时支持当前用户配置及当前系统配置两个作用范围。
创建配置文件
配置文件涉及到作用域(scope)、文件名(filename)、组织名(organization)、程序名(application)、配置格式(format)等,下面是可用的构造函数:
QSettings(const QString &organization, const QString &application = QString(), QObject *parent = Q_NULLPTR) //1
QSettings(Scope scope, const QString &organization, const QString &application = QString(), QObject *parent = Q_NULLPTR) //2
QSettings(Format format, Scope scope, const QString &organization, const QString &application = QString(), QObject *parent = Q_NULLPTR) //3
QSettings(const QString &fileName, Format format, QObject *parent = Q_NULLPTR) //3
QSettings(QObject *parent = Q_NULLPTR)
构造方式1在win下自动在注册表读写,2也一样
3如果设置为ini类型会在”C:/Users/XXXXX/AppData/Roaming/”用户范围建立ini文件,”C:/ProgramData/”系统范围
4可以指定文件名和类型
配置格式
Constant | Value | Description |
QSettings::NativeFormat | 0 | Store the settings using the most appropriate storage format for the platform. On Windows, this means the system registry; on macOS and iOS, this means the CFPreferences API; on Unix, this means textual configuration files in INI format. |
QSettings::Registry32Format | 2 | Windows only: Explicitly access the 32-bit system registry from a 64-bit application running on 64-bit Windows. On 32-bit Windows or from a 32-bit application on 64-bit Windows, this works the same as specifying NativeFormat. This enum value was added in Qt 5.7. |
QSettings::Registry64Format | 3 | Windows only: Explicitly access the 64-bit system registry from a 32-bit application running on 64-bit Windows. On 32-bit Windows or from a 64-bit application on 64-bit Windows, this works the same as specifying NativeFormat. This enum value was added in Qt 5.7. |
QSettings::IniFormat | 1 | Store the settings in INI files. |
QSettings::InvalidFormat | 16 | Special value returned by registerFormat(). |
作用域
Q |