ConfigStore
Provides thread-safe read/write access to a single INI-format QSettings file.
Every public method acquires an internal QMutex before touching the file, so a single ConfigStore instance may be shared across threads. Backend instances are created locally inside each call, so there is no long-lived handle to worry about.
Methods that operate on a specific key return false (or a safe default) when the underlying file path is absent, unreadable, or otherwise inaccessible, rather than emitting errors.
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
ConfigStore explicit | Constructs a ConfigStore bound to the given INI file. | |
QString | filePath const | Returns the file path this store was constructed with. |
QVariant | readValue const | Reads a single value from the store. |
bool | writeValue | Writes a single value to the store and flushes immediately. |
bool | contains const | Checks whether a key exists in the store. |
bool | removeValue | Removes a single key from the store and flushes immediately. |
bool | moveValue | Moves a value from one key (and optionally group) to another. |
QStringList | keysInGroup const | Lists keys stored under a given group. |
bool | sync | Flushes any unsynced in-memory changes to disk. |
Status | status const | Returns the current status of the underlying file. |
bool | backup const | Creates a backup copy of the settings file. |
bool | readBool const | Reads a boolean value, falling back to defaultValue when absent or inaccessible. |
double | readDouble const | Reads a double value, falling back to defaultValue when absent or inaccessible. |
int | readInt const | Reads an integer value, falling back to defaultValue when absent or inaccessible. |
QString | readString const | Reads a string value, falling back to defaultValue when absent or inaccessible. |
bool | writeBool | Writes a boolean value and flushes immediately. |
bool | writeDouble | Writes a double value and flushes immediately. |
bool | writeInt | Writes an integer value and flushes immediately. |
bool | writeString | Writes a string value and flushes immediately. |
explicit
ConfigStore
Section titled “ConfigStore”Constructs a ConfigStore bound to the given INI file.
The file is not opened at construction time; it is opened lazily on first access.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
filePath | const QString& | Absolute path to the INI file. When empty (the default), the store is unbound and every accessor returns its default or false. |
const
filePath
Section titled “filePath”Returns the file path this store was constructed with.
const
readValue
Section titled “readValue”Reads a single value from the store.
Returns
Section titled “Returns”The stored value, or defaultValue when the key is missing or unreadable.
This method is read-only and never modifies the file.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to look up. |
defaultValue | const QVariant& | Value returned when key is absent or the file is inaccessible. |
group | const QString& | Optional INI group prefix (e.g. "Network"). Empty for the root group. |
writeValue
Section titled “writeValue”Writes a single value to the store and flushes immediately.
Returns
Section titled “Returns”true when the write and subsequent sync succeeded; false when the key is empty, the file is inaccessible, or the sync failed.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to write. Must be non-empty. |
value | const QVariant& | The value to store. |
group | const QString& | Optional INI group prefix. Empty for the root group. |
const
contains
Section titled “contains”Checks whether a key exists in the store.
Returns
Section titled “Returns”true when the key is present and the file is accessible.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to look up. |
group | const QString& | Optional INI group prefix. Empty for the root group. |
removeValue
Section titled “removeValue”Removes a single key from the store and flushes immediately.
Returns
Section titled “Returns”true when the removal and subsequent sync succeeded; false when the key is empty, the file is inaccessible, or the sync failed.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to remove. Must be non-empty. |
group | const QString& | Optional INI group prefix. Empty for the root group. |
moveValue
Section titled “moveValue”Moves a value from one key (and optionally group) to another.
Returns
Section titled “Returns”true always, except when the file is inaccessible or either key is empty.
This method is intentionally non-destructive:
- If
oldKeydoes not exist, the call succeeds as a no-op. - If
newKeyalready exists at the destination, the existing value is preserved and the source is not moved.
These semantics make repeated migrations safe when newer configuration versions may already contain the destination key.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
oldKey | const QString& | Source key. Must be non-empty. |
oldGroup | const QString& | Source group prefix. Empty for the root group. |
newKey | const QString& | Destination key. Must be non-empty. |
newGroup | const QString& | Destination group prefix (defaults to the root group). |
const
keysInGroup
Section titled “keysInGroup”Lists keys stored under a given group.
Returns
Section titled “Returns”A list of keys (without the group prefix) under group, or an empty list when the file is inaccessible.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
group | const QString& | Group prefix to filter by. Empty returns all keys in the file. |
Flushes any unsynced in-memory changes to disk.
Returns
Section titled “Returns”true when the sync succeeded; false when the file is inaccessible.
const
status
Section titled “status”Returns the current status of the underlying file.
Returns
Section titled “Returns”One of:
- NoError when the file is accessible and valid.
- AccessError when the file path is empty, nonexistent, or not readable/writable.
- FormatError when the file exists but contains malformed INI content.
Internally this syncs first so the status reflects the latest on-disk state.
const
backup
Section titled “backup”Creates a backup copy of the settings file.
Returns
Section titled “Returns”true when the backup was created; false when the source file does not exist or is inaccessible.
Any pre-existing “.bak file is replaced. Backups are explicit and must succeed before callers mutate a settings file.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
backupPath | QString* | Optional output parameter set to the absolute path of the backup file ("<filePath>.bak") on success. |
const
readBool
Section titled “readBool”Reads a boolean value, falling back to defaultValue when absent or inaccessible.
Returns
Section titled “Returns”The stored value converted via QVariant::toBool().
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to look up. |
defaultValue | bool | Value returned when the key is missing or unreadable. |
group | const QString& | Optional INI group prefix. |
const
readDouble
Section titled “readDouble”Reads a double value, falling back to defaultValue when absent or inaccessible.
Returns
Section titled “Returns”The stored value converted via QVariant::toDouble().
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to look up. |
defaultValue | double | Value returned when the key is missing or unreadable. |
group | const QString& | Optional INI group prefix. |
const
readInt
Section titled “readInt”Reads an integer value, falling back to defaultValue when absent or inaccessible.
Returns
Section titled “Returns”The stored value converted via QVariant::toInt().
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to look up. |
defaultValue | int | Value returned when the key is missing or unreadable. |
group | const QString& | Optional INI group prefix. |
const
readString
Section titled “readString”Reads a string value, falling back to defaultValue when absent or inaccessible.
Returns
Section titled “Returns”The stored value converted via QVariant::toString().
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to look up. |
defaultValue | const QString& | Value returned when the key is missing or unreadable. |
group | const QString& | Optional INI group prefix. |
writeBool
Section titled “writeBool”Writes a boolean value and flushes immediately.
Returns
Section titled “Returns”true when the write and sync succeeded; false otherwise.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to write. Must be non-empty. |
value | bool | The boolean value to store. |
group | const QString& | Optional INI group prefix. |
writeDouble
Section titled “writeDouble”Writes a double value and flushes immediately.
Returns
Section titled “Returns”true when the write and sync succeeded; false otherwise.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to write. Must be non-empty. |
value | double | The double value to store. |
group | const QString& | Optional INI group prefix. |
writeInt
Section titled “writeInt”Writes an integer value and flushes immediately.
Returns
Section titled “Returns”true when the write and sync succeeded; false otherwise.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to write. Must be non-empty. |
value | int | The integer value to store. |
group | const QString& | Optional INI group prefix. |
writeString
Section titled “writeString”Writes a string value and flushes immediately.
Returns
Section titled “Returns”true when the write and sync succeeded; false otherwise.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
key | const QString& | The key to write. Must be non-empty. |
value | const QString& | The string value to store. |
group | const QString& | Optional INI group prefix. |
Public Types
Section titled “Public Types”| Name | Description |
|---|---|
Status | Describes the current state of the underlying settings file. |
Status
Section titled “Status”Describes the current state of the underlying settings file.
Values mirror QSettings::Status so callers can inspect them without depending on Qt directly in client code.
| Value | Description |
|---|---|
NoError | No error detected during the last operation. |
AccessError | The file does not exist, is not readable, or its path is invalid. |
FormatError | The file exists but could not be parsed as valid INI content. |