:: printable version ::

XML application preferences handler

::description ::changelog ::requirements ::features ::usage ::


The XMLPreferences class allows to store application settings in plain text files using XML format. Stored settings may be read using the XMLPreferences class or other XML parsers. The class supports many Qt data types and allows settings to be organized in sections.

The following data types are currently supported. Custom data types can be easily added (please refer to the comments in the .cpp file).

The following data types are only available if the QT_CORE_ONLY macro has not been defined (you might need this if you do not link against the QtGui module):

The class requires both the XmlWriter and Base64 classes from The OSDaB Project and the libxml2 library.

A small example application can be downloaded below. The package contains all the required source files, the libxml2 headers and the the Win32 libraries build and distributed by Igor Zlatkovic. Unix users should have a working libxml2-devel installation (I'd wonder if they don't have one already!).





Usage example

Here is a little usage example for storing settings to a file:

XMLPreferences xml("MyApplication", "MyCompany"); xml.setInt("world_takeover", "days_missing", 5); xml.setByteArray("appearance", "window_state", saveState()); xml.setRect("appearance", "geometry", frameGeometry());

And here is the code to load the previously stored settings:

XMLPreferences xml("MyApplication", "MyCompany"); if (!xml.load(mySettingsPath)) // ERROR HANDLING?
bool ok; int timeout = xml.getInt("world_takeover", "days_missing", &ok); QByteArray b = xml.getByteArray("appearance", "window_state"); if (!b.isEmpty()) restoreState(b); QRect r = xml.getRect("appearance", "geometry"); if (r.isValid()) setGeometry(r);
:: index :: top ::