定义:
QSettings 类提供与平台无关的持久应用程序设置。
官方例子:
QSettings settings("MySoft", "Star Runner");
settings.setValue("editor/wrapMargin", 68);
int margin = settings.value("editor/wrapMargin").toInt();
1.构造函数
QSettings::QSettings(const QString &organization, const QString &application, QObject *parent)
: QObject(*QSettingsPrivate::create(NativeFormat, UserScope, organization, application),
parent)
{
}
QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope,
const QString &organization, const QString &application)
{
return new QConfFileSettingsPrivate(format, scope, organization, application);
}
QConfFileSettingsPrivate::QConfFileSettingsPrivate(QSettings::Format format,
QSettings::Scope scope,
const QString &organization,
const QString &application)
: QSettingsPrivate(format, scope, organization, application),
nextPosition(0x40000000) // big positive number
{
initFormat();
QString org = organization;
if (org.isEmpty()) {
setStatus(QSettings::AccessError);
org = QLatin1String("Unknown Organization");
}
QString appFile = org + QDir::separator() + application + extension;
QString orgFile = org + extension;
if (scope == QSettings::UserScope) {
Path userPath = getPath(format, QSettings::UserScope);
if (!application.isEmpty())
confFiles.append(QConfFile::fromName(userPath.path + appFile, true));
confFiles.append(QConfFile::fromName(userPath.path + orgFile, true));
}
Path systemPath = getPath(format, QSettings::SystemScope);
#if defined(Q_XDG_PLATFORM) && !defined(QT_NO_STANDARDPATHS)
// check if the systemPath wasn't overridden by QSettings::setPath()
if (!systemPath.userDefined) {
// Note: We can't use QStandardPaths::locateAll() as we need all the
// possible files (not just the existing ones) and there is no way
// to exclude user specific (XDG_CONFIG_HOME) directory from the search.
QStringList dirs = QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation);

本文详细介绍了Qt中的QSettings类,该类用于实现跨平台的应用程序设置存储。文章深入探讨了其构造函数、setValue方法及value方法的工作原理,并展示了如何通过这些方法来读写配置。
最低0.47元/天 解锁文章
336

被折叠的 条评论
为什么被折叠?



