【问题标题】:QSettings clear, what does it do?QSettings clear,有什么作用?
【发布时间】:2015-08-08 02:59:08
【问题描述】:

文档将QSettings::clear 函数描述为:

删除与此关联的主要位置中的所有条目 QSettings 对象。

后备位置中的条目不会被删除。

但这意味着什么?主要位置和后备位置是什么???

【问题讨论】:

标签: qt qsettings


【解决方案1】:

主要位置取决于操作系统和您的设置。对于 Windows,这是注册表等。来自QSettings 的文档:

假设您创建了一个 QSettings 对象,其组织名称为 MySoft,应用程序名称为 Star Runner。当您查找一个值时,最多会按此顺序搜索四个位置:

  • Star Runner 应用程序的用户特定位置
  • MySoft 为所有应用程序提供的用户特定位置
  • Star Runner 应用程序的系统范围位置
  • MySoft 为所有应用程序提供系统范围的位置

主要位置是最具体的位置:通常是您的应用程序的用户特定位置。

您可以为所有用户/应用程序提供共享默认值。但如果您拨打clear(),它们不会被删除。仅清除用户应用程序特定的值。

示例

如果您使用公司和应用程序名称或使用默认构造函数初始化QSettings 对象,则主要值是应用程序用户特定值。大多数应用程序都是这种情况。如果您只是使用默认构造函数创建 QSettings 对象,则使用来自 QApplication 的值(应用程序名称和组织名称)。

QSettings settings("MySoft", "Star Runner");
settings.clear();
// or
QSettings settings(); // use the values from QApplication
settings.clear();

如果你用其他值初始化QSettings对象,你可以选择另一个主“存储”:

QSettings settings("MySoft");
settings.clear(); // clears values for whole company if possible.

QSettings settings(QSettings::SystemScope, "MySoft", "Star Runner");
settings.clear(); // clears system wide settings for the application.

QSettings settings(QSettings::SystemScope, "MySoft");
settings.clear(); // clears system wide settings for the company.

最后三种情况很少见,没有多大意义。此外,应用程序需要写入系统范围设置的权限。

【讨论】:

    猜你喜欢
    • 2012-10-04
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    相关资源
    最近更新 更多