PersistentSettingsReader Class | Extending Qt Creator Manual

Extending Qt Creator Manual | PersistentSettingsReader

Extending Qt Creator Manual 4.6.0

# PersistentSettingsReader Class

(Utils::PersistentSettingsReader)

The PersistentSettingsReader class reads a QVariantMap of arbitrary, nested data structures from an XML file. More...

Header: | #include <PersistentSettingsReader>

- List of all members, including inherited members

## Public Functions

| PersistentSettingsReader()
bool | load(const FileName &fileName)
QVariant | restoreValue(const QString &variable, const QVariant &defaultValue = QVariant()) const
QVariantMap | restoreValues() const

## Detailed Description

The PersistentSettingsReader class reads a QVariantMap of arbitrary, nested data structures from an XML file.

Handles all string-serializable simple types and QVariantList and QVariantMap. Example:

      <qtcreator>
          <data>
              <variable>ProjectExplorer.Project.ActiveTarget</variable>
              <value type="int">0</value>
          </data>
          <data>
              <variable>ProjectExplorer.Project.EditorSettings</variable>
              <valuemap type="QVariantMap">
                  <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
              </valuemap>
          </data>

When parsing the structure, a parse stack of ParseValueStackEntry is used for each <data> element. ParseValueStackEntry is a variant/union of:

- simple value
- map
- list

You can register string-serialize functions for custom types by registering them in the Qt Meta type system. Example:

      QMetaType::registerConverter(&MyCustomType::toString);
      QMetaType::registerConverter<QString, MyCustomType>(&myCustomTypeFromString);

When entering a value element ( `<value>` / `<valuelist>` , `<valuemap>` ), entry is pushed accordingly. When leaving the element, the QVariant-value of the entry is taken off the stack and added to the stack entry below (added to list or inserted into map). The first element of the stack is the value of the <data> element.

See also Utils::PersistentSettingsWriter.

## Member Function Documentation

### PersistentSettingsReader::PersistentSettingsReader()

Default constructs an instance of PersistentSettingsReader.

### bool PersistentSettingsReader::load(const FileName &fileName)

### QVariant PersistentSettingsReader::restoreValue(const QString &variable, const QVariant &defaultValue = QVariant()) const

### QVariantMap PersistentSettingsReader::restoreValues() const