|
1 组 写入
void Settings::writeSettings()
  {
QSettings settings("Seahouse-pub", "Settings Test");

settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
}读出
void Settings::readSettings()
  {
QSettings settings("Seahouse-pub", "Settings Test");

settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(400, 400)).toSize());
move(settings.value("pos", QPoint(200, 200)).toPoint());
settings.endGroup();
}2 文件 QSettings settings(fileName, QSettings::IniFormat);3 数组 读出
 struct Login {
QString userName;
QString password;
};
QList<Login> logins;


QSettings settings;
int size = settings.beginReadArray("logins");
 for (int i = 0; i < size; ++i) {
settings.setArrayIndex(i);
Login login;
login.userName = settings.value("userName").toString();
login.password = settings.value("password").toString();
logins.append(login);
}
settings.endArray();写入
 struct Login {
QString userName;
QString password;
};
QList<Login> logins;


QSettings settings;
settings.beginWriteArray("logins");
 for (int i = 0; i < logins.size(); ++i) {
settings.setArrayIndex(i);
settings.setValue("userName", logins.at(i).userName);
settings.setValue("password", logins.at(i).password);
}
settings.endArray();
|