QSettings配置读写-win注册表操作-ini文件读写

QSettings提供了一套跨平台的配置文件读写机制,支持win下的注册表和ini文件操作。它涉及作用域、组织、程序名、配置格式等参数。在win下,系统范围配置会检查用户范围,而自定义格式可以通过registerFormat方法实现。QSettings还支持beginGroup、endGroup进行分组操作,以及beginReadArray、beginWriteArray处理数组。默认路径可以通过setPath函数调整。
摘要由CSDN通过智能技术生成
 

介绍

官方帮助文档: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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值