QSettings 读写注册表

来源:互联网 发布:linux的shell用法 编辑:程序博客网 时间:2024/06/16 07:08

参考:QSettings读写注册表、配置文件

不分组

// 写注册表void writeRegistry(){    // 公司名称    QCoreApplication::setOrganizationName(QString("Digia"));    // App 名称    QCoreApplication::setApplicationName(QString("frainSuperApp"));    QSettings settings(QSettings::NativeFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());    // 写入键值对    settings.setValue("Name", "Qt Creator");    settings.setValue("Version", 5);}

效果图

这里写图片描述

// 读注册表void readRegistry(){    QCoreApplication::setOrganizationName(QString("Digia"));    QCoreApplication::setApplicationName(QString("frainSuperApp"));    QSettings settings(QSettings::NativeFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());    QString strName = settings.value("Name").toString();    int nVersion = settings.value("Version").toInt();}

分组

void writeRegistry(){    QCoreApplication::setOrganizationName(QString("Digia"));    QCoreApplication::setApplicationName(QString("frainSuperApp"));    QSettings settings(QSettings::NativeFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());    settings.beginGroup("Qt6.5");    settings.setValue("Name", "Qt Creator");    settings.setValue("Version", "6.5");    settings.endGroup();    settings.beginGroup("Qt6.6");    settings.setValue("Name", "Qt Creator");    settings.setValue("Version", "6.6");    settings.endGroup();}

效果图

这里写图片描述

void readRegistry(){    QCoreApplication::setOrganizationName(QString("Digia"));    QCoreApplication::setApplicationName(QString("frainSuperApp"));    QSettings settings(QSettings::NativeFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());    settings.beginGroup("Qt6.5");    QString strName = settings.value("Name").toString();    QString nVersion = settings.value("Version").toString();    settings.endGroup();    settings.beginGroup("Qt6.6");    strName = settings.value("Name").toString();    nVersion = settings.value("Version").toString();    settings.endGroup();}

相关博客: QSettings 读写配置文件

原创粉丝点击