Qtopia Home - Classes - Hierachy - Annotated - Functions - Qt Embedded |

# Config Class Reference

The Config class provides for saving application configuration state. More...

`#include <qtopia/config.h>`

List of all member functions.

## Public Members

- enum Domain { File, User }
- Config ( const QString & name, Domain domain = User )
- ~Config ()
- bool operator== ( const Config & other ) const
- bool operator!= ( const Config & other ) const
- bool isValid () const
- bool hasKey ( const QString & key ) const
- void setGroup ( const QString & gname )
- void writeEntry ( const QString & key, const char * value )
- void writeEntry ( const QString & key, const QString & value )
- void writeEntryCrypt ( const QString & key, const QString & value )
- void writeEntry ( const QString & key, int num )
- void writeEntry ( const QString & key, const QStringList & lst, const QChar & sep )
- void writeEntry ( const QString & key, const QStringList & lst )
- void writeEntry ( const QString & key, const QByteArray & byteArray )
- void removeEntry ( const QString & key )
- QString readEntry ( const QString & key, const QString & deflt = QString::null ) const
- QString readEntryCrypt ( const QString & key, const QString & deflt = QString::null ) const
- int readNumEntry ( const QString & key, int deflt = -1 ) const
- bool readBoolEntry ( const QString & key, bool deflt = FALSE ) const
- QStringList readListEntry ( const QString & key, const QChar & sep ) const
- QStringList readListEntry ( const QString & key ) const
- QByteArray readByteArrayEntry ( const QString & key ) const
- QByteArray readByteArrayEntry ( const QString & key, const QByteArray & dflt ) const
- void clearGroup ()
- void removeGroup ()
- void removeGroup ( const QString & g )
- QStringList allGroups () const

## Static Public Members

- long timeStamp ( const QString & name, Domain domain = User )

## Detailed Description

The Config class provides for saving application configuration state.

You should keep a Config in existence only while you do not want others to be able to change the state. There is no locking currently, but there may be in the future.

Note that in Qtopia before 1.6, the 'const' forms of the read functions where not available.

See also Qtopia Classes.

## Member Type Documentation

### Config::Domain

- `Config::File`
- `Config::User`

See Config() for details.

## Member Function Documentation

### Config::Config ( const QString & name, Domain domain = User )

Constructs a configuration object that will load or create a configuration with the given name in the given domain.

After construction, call setGroup() since almost every other function works in terms of the 'current group'.

In the default Domain, User, the configuration is user-specific, and the name should not contain "/". This name should be globally unique.

In the File Domain, name is an absolute filename.

### Config::~Config ()

Writes any changes to disk and destroys the in-memory object.

### QStringList Config::allGroups () const

Returns the list of all groups in the Config.

First availability: Qtopia 2.0

### void Config::clearGroup ()

Removes all entries from the current group.

See also removeEntry() and removeGroup().

### bool Config::hasKey ( const QString & key ) const

Returns TRUE if the current group has an entry called key; otherwise returns FALSE.

### bool Config::isValid () const

Returns TRUE if the Config is in a valid state; otherwise returns FALSE.

### bool Config::operator!= ( const Config & other ) const

Tests for inequality with other. Config objects are equal if they refer to the same filename.

See also operator==().

### bool Config::operator== ( const Config & other ) const

Tests for equality with other. Config objects are equal if they refer to the same filename.

See also operator!=().

### bool Config::readBoolEntry ( const QString & key, bool deflt = FALSE ) const

Returns the boolean entry stored (as an integer) using key, defaulting to deflt if there is no entry for the given key.

See also writeEntry().

### QByteArray Config::readByteArrayEntry ( const QString & key ) const

Returns the QByteArray stored using key. Returns an empty array if no matching key is found.

First availability: Qtopia 1.6

### QByteArray Config::readByteArrayEntry ( const QString & key, const QByteArray & dflt ) const

Returns the QByteArray stored using key. Returns dflt if no matching key is found.

First availability: Qtopia 1.6

### QString Config::readEntry ( const QString & key, const QString & deflt = QString::null ) const

Returns the string entry for key, defaulting to deflt if there is no entry for the given key.

See also writeEntry().

### QString Config::readEntryCrypt ( const QString & key, const QString & deflt = QString::null ) const

Returns the unencrypted string entry for the encrypted entry stored using key, defaulting to deflt if there is no entry for the given key.

See also writeEntryCrypt().

### QStringList Config::readListEntry ( const QString & key, const QChar & sep ) const

Returns the string list entry stored using key and with sep as the separator.

These entries are stored as a single string, with each element separated by sep.

See also writeEntry().

### QStringList Config::readListEntry ( const QString & key ) const

Returns the string list entry stored using key and with the escaped seperator convention described in writeListEntry().

First availability: Qtopia 2.0

### int Config::readNumEntry ( const QString & key, int deflt = -1 ) const

Returns the integer entry stored using key, defaulting to deflt if there is no entry for the given key.

See also writeEntry().

### void Config::removeEntry ( const QString & key )

Removes the key entry from the current group. Does nothing if there is no such entry.

See also writeEntry() and clearGroup().

### void Config::removeGroup ()

Removes the current group (and all its entries).

The current group becomes unset.

First availability: Qtopia 2.0

### void Config::removeGroup ( const QString & g )

Removes the current group (and all its entries).

The current group becomes unset.

First availability: Qtopia 2.0

### void Config::setGroup ( const QString & gname )

Sets the current group for subsequent reading and writing of entries to gname. Grouping allows the application to partition the namespace.

This function must be called prior to any reading or writing of entries.

The gname must not be empty.

See also writeEntry(), readEntry(), readListEntry(), readNumEntry() and readBoolEntry().

### long Config::timeStamp ( const QString & name, Domain domain = User )`[static]`

Returns the time stamp for the config identified by name. The time stamp represents the time the config was last committed to storage. Returns 0 if there is no time stamp available for the config.

A domain can optionally be specified and defaults to User. See Config() for details.

First availability: Qtopia 2.0

### void Config::writeEntry ( const QString & key, const char * value )

Writes a (key, value) entry to the current group.

See also readEntry().

### void Config::writeEntry ( const QString & key, const QString & value )

Writes a (key, value) entry to the current group.

See also readEntry().

### void Config::writeEntry ( const QString & key, int num )

Writes a (key, num) entry to the current group.

See also readNumEntry() and readBoolEntry().

### void Config::writeEntry ( const QString & key, const QStringList & lst, const QChar & sep )

Writes a (key, lst) entry to the current group. The list is separated by sep, so the strings must not contain that character.

See also readListEntry().

### void Config::writeEntry ( const QString & key, const QStringList & lst )

Writes a (key, lst) entry to the current group.

The list is separated by the two characters "^e", and "^" withing the strings is replaced by "^^", such that the strings may contain any character, including "^".

Null strings are also allowed, and are recorded as "^0" in the string.

First availability: Qtopia 2.0

See also readListEntry().

### void Config::writeEntry ( const QString & key, const QByteArray & byteArray )

Writes a (key, byteArray) entry to the current group. The byteArray is stored as a base64 encoded string.

First availability: Qtopia 1.6

### void Config::writeEntryCrypt ( const QString & key, const QString & value )

Writes a weakly encrypted (key, value) entry to the current group.

Note that the degree of protection offered by the encryption is only sufficient to avoid the most casual observation of the configuration files.

See also readEntryCrypt().

This file is part of the Qtopia platform, copyright © 1995-2004 Trolltech, all rights reserved.