QT之setting注册表项

时间:2022-09-13 20:43:19

1.头文件

#include <QSettings>

2.read注册表项

void MainWindow::readSettings() // 读取窗口设置
{
    QSettings settings("yangfeilinux", "myMdi");
    QPoint pos = settings.value("pos", QPoint(0, 0)).toPoint();
    QSize size = settings.value("size", QSize(1366, 706)).toSize();
    move(pos);
    resize(size);
}

3.写注册表项

void MainWindow::writeSettings() // 写入窗口设置
{
    QSettings settings("yafeilinux", "myMdi");
    settings.setValue("pos", pos());   // 写入位置信息
    settings.setValue("size", size()); // 写入大小信息
}

4.注册表目录

HKEY_CURRENT_USER\Software\yafeilinux