Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QSettings Class Reference

The QSettings class provides persistent platform-indendent GUI application settings. More...

#include <QSettings>

Inherits QCoreSettings.

Writable Properties

Public Functions

Public Slots

Signals

Static Public Members

Protected Functions


Detailed Description

The QSettings class provides persistent platform-indendent GUI application settings.

Users normally expect an application to remember its settings (window sizes and positions, options, etc.) across sessions. This information is often stored in the system registry on Windows, and in XML preferences files on Mac OS X. On X11, in the absense of a standard, many applications (including the KDE applications) use INI text files.

QSettings is an abstraction around these technologies, enabling you to save and restore application settings in a portable manner.

QSettings inherits most of its functionality from QCoreSettings. If your application links against the QtGui library, you can use QSettings rather than QCoreSettings. QSettings's API is based on QVariant instead of QCoreVariant, which allows you to save GUI-related types such as QRect, QSize, and QColor.

See the QCoreSettings documentation for a detailed description of how to use this class.


Member Function Documentation

QSettings::QSettings ( const QString & organization, const QString & application = QString(), QObject * parent = 0 )

Constructs a QSettings object for accessing settings of the application called application from the organization with the Internet domain name organization, and with parent parent.

Example:

    QSettings settings("www.technopro.co.jp", "Facturo-Pro");

The scope is Qt::UserScope and the format is Qt::NativeFormat.

QSettings::QSettings ( Qt::SettingsScope scope, const QString & organization, const QString & application = QString(), QObject * parent = 0 )

Constructs a QSettings object for accessing settings of the application called application from the organization with the Internet domain name organization, and with parent parent.

If scope is Qt::UserScope, the QSettings object searches user-specific settings first, before it seaches system-wide settings as a fallback. If scope is Qt::SystemScope, the QSettings object ignores user-specific settings and provides access to system-wide settings.

The storage format is always Qt::NativeFormat.

If no application name is given, the QSettings object will only access the organization-wide locations.

QSettings::QSettings ( Qt::SettingsFormat format, Qt::SettingsScope scope, const QString & organization, const QString & application = QString(), QObject * parent = 0 )

Constructs a QSettings object for accessing settings of the application called application from the organization with the Internet domain name organization, and with parent parent.

If scope is Qt::UserScope, the QSettings object searches user-specific settings first, before it seaches system-wide settings as a fallback. If scope is Qt::SystemScope, the QSettings object ignores user-specific settings and provides access to system-wide settings.

If format is Qt::NativeFormat, the native API is used for storing settings. If format is Qt::IniFormat, the INI format is used.

If no application name is given, the QSettings object will only access the organization-wide locations.

QSettings::QSettings ( const QString & fileName, Qt::SettingsFormat format, QObject * parent = 0 )

Constructs a QSettings object for accessing the settings stored in the file called fileName, with parent parent. If the file doesn't already exist, it is created.

If format is Qt::NativeFormat, the meaning of fileName depends on the platform. On Unix/X11, fileName is the name of an INI file. On Mac OS X, fileName is the name of a .plist file. On Windows, fileName is a path in the system registry.

If format is Qt::IniFormat, fileName is the name of an INI file.

QSettings::QSettings ( QObject * parent = 0 )

Constructs a QSettings object for accessing settings of the application and organization set previously with a call to QCoreApplication::setProductInfo().

The scope is Qt::UserScope and the format is Qt::NativeFormat.

The code

    QSettings settings("www.technopro.co.jp", "Facturo-Pro");

is equivalent to

    qApp->setProductInfo("www.technopro.co.jp", "Facturo-Pro");
    QSettings settings;

If QApplication::setProductInfo() has not been previously called, the QSettings object will not be able to read or write any settings, and status() will return AccessError.

QSettings::~QSettings ()

Destroys the QSettings object. Any unsaved changes will be written to permanent storage at that point.

void QSettings::setValue ( const QString & key, const QVariant & value )

Sets the value of setting key to value.

If the key already exists, the previous value is overwritten.

This function is the same as QCoreSettings::setValue(), except that the second parameter is of type QVariant instead of QCoreVariant.

See also value().

QVariant QSettings::value ( const QString & key, const QVariant & defaultValue = QVariant() ) const

Returns the value for setting key. If the setting doesn't exist, returns defaultValue.

If no default value is specified, a default QVariant is returned.

This function is the same as QCoreSettings::setValue(), except that the second parameter and the return value are of type QVariant instead of QCoreVariant.

See also setValue().


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp2