Main Page · All Classes ·
Public Functions
QXmlPut Class Reference

Is used to write to the XML document and save it. More...

Public Functions

 QXmlPut (const QString &rootTag)
 
 QXmlPut (const QString &rootTag, const QString &xmlVersion, const QString &encoding, bool standalone, const QString &docType=QString(), const QString &publicId=QString(), const QString &systemId=QString())
 
 QXmlPut (const QXmlGet &xmlGet)
 
QDomDocument document () const
 
void putComment (const QString &comment)
 
void putSingleTag (const QString &tagName)
 
void putString (const QString &tagName, const QString &value, bool asCDATA=false)
 
void putStringList (const QString &tagName, const QStringList &values, bool asCDATA=false)
 
void putInt (const QString &tagName, int value)
 
void putIntVector (const QString &tagName, const QVector< int > &values)
 
void putDouble (const QString &tagName, double value, char format='g', int precision=15)
 
void putDoubleVector (const QString &tagName, const QVector< double > &values, char format='g', int precision=15)
 
void putBool (const QString &tagName, bool value, QXmlPutGet::BoolFormat format=QXmlPutGet::bfYesNo)
 
void putBoolVector (const QString &tagName, const QVector< bool > &values, QXmlPutGet::BoolFormat format=QXmlPutGet::bfYesNo)
 
void putColor (const QString &tagName, const QColor &value)
 
void putSize (const QString &tagName, const QSize &value)
 
void putSizeF (const QString &tagName, const QSizeF &value)
 
void putPoint (const QString &tagName, const QPoint &value)
 
void putPointF (const QString &tagName, const QPointF &value)
 
void putRect (const QString &tagName, const QRect &value)
 
void putRectF (const QString &tagName, const QRectF &value)
 
void putDate (const QString &tagName, const QDate &value)
 
void putTime (const QString &tagName, const QTime &value)
 
void putDateTime (const QString &tagName, const QDateTime &value)
 
void putByteArray (const QString &tagName, const QByteArray &value, int blockWidth=2048, int compression=9)
 
void putImage (const QString &tagName, const QImage &value, const QString format=QString("PNG"), int blockWidth=2048)
 
void putPen (const QString &tagName, const QPen &value)
 
void putBrush (const QString &tagName, const QBrush &value)
 
void putFont (const QString &tagName, const QFont &value)
 
bool saveWidget (const QWidget *value, bool warnWhenUnsupported=true)
 
int saveWidgetsRecursive (const QWidget *parent, const QString &prefix="", const QString &suffix="", const QSet< const QWidget *> &exclude=QSet< const QWidget *>())
 
bool saveLineEdit (const QLineEdit *value)
 
bool saveAbstractButton (const QAbstractButton *value)
 
bool saveTextEdit (const QTextEdit *value)
 
bool savePlainTextEdit (const QPlainTextEdit *value)
 
bool saveSpinBox (const QSpinBox *value)
 
bool saveDoubleSpinBox (const QDoubleSpinBox *value)
 
bool saveComboBox (const QComboBox *value, bool items)
 
bool saveAbstractSlider (const QAbstractSlider *value)
 
bool saveDateTimeEdit (const QDateTimeEdit *value)
 
bool saveFontComboBox (const QFontComboBox *value)
 
bool saveGroupBox (const QGroupBox *value)
 
QXmlPut restricted ()
 
void descend (const QString &tagName)
 
QXmlPut descended (const QString &tagName)
 
bool rise ()
 
bool goTo (QDomElement parentElement)
 
QDomElement element () const
 
void setAttributeString (const QString &name, const QString &value)
 
void setAttributeInt (const QString &name, int value)
 
void setAttributeIntVector (const QString &name, const QVector< int > &value)
 
void setAttributeDouble (const QString &name, double value, char format='g', int precision=15)
 
void setAttributeDoubleVector (const QString &name, const QVector< double > &value, char format='g', int precision=15)
 
void setAttributeBool (const QString &name, bool value, QXmlPutGet::BoolFormat format=QXmlPutGet::bfYesNo)
 
void setAttributeBoolVector (const QString &name, const QVector< bool > &value, QXmlPutGet::BoolFormat format=QXmlPutGet::bfYesNo)
 
void setAttributeColor (const QString &name, const QColor &value)
 
QString toString (int spacesPerIndent=2) const
 
bool save (const QString &fileName, int spacesPerIndent=2) const
 

Detailed Description

Is used to write to the XML document and save it.

Constructor & Destructor Documentation

§ QXmlPut() [1/3]

QXmlPut::QXmlPut ( const QString &  rootTag)

Creates a new XML document with a root tag named rootTag. XML version is set to 1.0, encoding to UTF-8 and standalone to false.

§ QXmlPut() [2/3]

QXmlPut::QXmlPut ( const QString &  rootTag,
const QString &  xmlVersion,
const QString &  encoding,
bool  standalone,
const QString &  docType = QString(),
const QString &  publicId = QString(),
const QString &  systemId = QString() 
)

Creates a new XML document with a root tag named rootTag. And the specified XML parameters.

example:

The call

QXmlPut xmlPut("myRoot", "1.0", "UTF-8", true, "myDocType", "myPublicId", "mySystemId");

creates the following XML document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE myDocType PUBLIC 'myPublicId' 'mySystemId'>
<myRoot>
(...)
</myRoot>

§ QXmlPut() [3/3]

QXmlPut::QXmlPut ( const QXmlGet xmlGet)

Returns an QXmlPut instance located at the current position. This can be used to read and write to the XML document at the same time.

Member Function Documentation

§ document()

QDomDocument QXmlPut::document ( ) const
inline

Returns the QDomDocument this QXmlPut instance is using.

§ putComment()

void QXmlPut::putComment ( const QString &  comment)

Inserts a comment. Comments can't be read by QXmlGet and are meant for other humans reading the XML document in a text editor.

example output:

<!-- example comment -->

§ putSingleTag()

void QXmlPut::putSingleTag ( const QString &  tagName)

Inserts a single tag with name tagName. As with every tag, you can attach attributes to it by subsequent calls to setAttribute(...) functions.

example output:

<tagName>

§ putString()

void QXmlPut::putString ( const QString &  tagName,
const QString &  value,
bool  asCDATA = false 
)

Inserts a tag with name tagName which contains the string value. If the string contains many special characters like "<", ">" and linebreaks, you should consider setting asCDATA to true, so the string will be embedded in a CDATA-section which avoids escaping most of the special characters and thus makes it easier for users to read/modify the resulting XML document in a text editor.

Note that due to escaping mechanisms any content is allowed for value. Even if asCDATA is set to true and value itself contains a string like "<![CDATA[trick]]>", it will be saved in two disjoint CDATA sections, splitting the value string into "<![CDATA[trick]]" and ">", preserving the resulting XML validity aswell as the saved value.

example output:

<tagName>example text</tagName>
<tagName><![CDATA[example text]]></tagName>
See also
putStringList

§ putStringList()

void QXmlPut::putStringList ( const QString &  tagName,
const QStringList &  values,
bool  asCDATA = false 
)

Inserts a tag with name tagName which contains the string list values. If the strings contain many special characters like "<", ">" and linebreaks, you should consider setting asCDATA to true, so the strings will be embedded in a CDATA-section which avoids escaping most of the special characters and thus makes it easier for users to read/modify the resulting XML document in a text editor.

example output:

<tagName>
<li>first line</li>
<li>second line</li>
<li>third line</li>
</tagName>
See also
putString

§ putInt()

void QXmlPut::putInt ( const QString &  tagName,
int  value 
)

Inserts a tag with name tagName which contains the integer value.

example output:

<tagName>42</tagName>
See also
putDouble, putIntVector

§ putIntVector()

void QXmlPut::putIntVector ( const QString &  tagName,
const QVector< int > &  values 
)

Inserts a tag with name tagName which contains the integer vector value.

example output:

<tagName>0;1;1;2;3;5;8;13</tagName>
See also
putInt

§ putDouble()

void QXmlPut::putDouble ( const QString &  tagName,
double  value,
char  format = 'g',
int  precision = 15 
)

Inserts a tag with name tagName which contains the double value.

example output:

<tagName>3.1415</tagName>
See also
putInt, putDoubleVector

§ putDoubleVector()

void QXmlPut::putDoubleVector ( const QString &  tagName,
const QVector< double > &  values,
char  format = 'g',
int  precision = 15 
)

Inserts a tag with name tagName which contains the double vector value.

example output:

<tagName>0.1;0.24;0.52;-0.22</tagName>
See also
putDouble

§ putBool()

void QXmlPut::putBool ( const QString &  tagName,
bool  value,
QXmlPutGet::BoolFormat  format = QXmlPutGet::bfYesNo 
)

Inserts a tag with name tagName which contains the bool value.

Depending on the specified format (see QXmlPutGet::BoolFormat), the boolean value is represented with different strings.

example output:

<tagName>yes</tagName>
See also
putBoolVector

§ putBoolVector()

void QXmlPut::putBoolVector ( const QString &  tagName,
const QVector< bool > &  values,
QXmlPutGet::BoolFormat  format = QXmlPutGet::bfYesNo 
)

Inserts a tag with name tagName which contains the bool vector value.

Depending on the specified format (see QXmlPutGet::BoolFormat), the boolean values are represented with different strings.

example output:

<tagName>yes;no;no;yes;no;yes</tagName>
See also
putBool

§ putColor()

void QXmlPut::putColor ( const QString &  tagName,
const QColor &  value 
)

Inserts a tag with name tagName which contains the QColor value.

If the color contains no transparency component (i.e. alpha is 255), the color is saved in the format "#rrggbb". If it contains alpha, it is saved as "#rrggbbaa".

example output:

<tagName>#2280ff</tagName>

§ putSize()

void QXmlPut::putSize ( const QString &  tagName,
const QSize &  value 
)

Inserts a tag with name tagName which contains the QSize value.

example output:

<tagName width="640" height="480">
See also
putSizeF

§ putSizeF()

void QXmlPut::putSizeF ( const QString &  tagName,
const QSizeF &  value 
)

Inserts a tag with name tagName which contains the QSizeF value.

example output:

<tagName width="122.4" height="10.95">
See also
putSize

§ putPoint()

void QXmlPut::putPoint ( const QString &  tagName,
const QPoint &  value 
)

Inserts a tag with name tagName which contains the QPoint value.

example output:

<tagName x="640" y="480">
See also
putPointF

§ putPointF()

void QXmlPut::putPointF ( const QString &  tagName,
const QPointF &  value 
)

Inserts a tag with name tagName which contains the QPointF value.

example output:

<tagName x="122.4" y="10.95">
See also
putPoint

§ putRect()

void QXmlPut::putRect ( const QString &  tagName,
const QRect &  value 
)

Inserts a tag with name tagName which contains the QRect value.

example output:

<tagName left="10" top="15" width="640" height="480">
See also
putRectF

§ putRectF()

void QXmlPut::putRectF ( const QString &  tagName,
const QRectF &  value 
)

Inserts a tag with name tagName which contains the QRectF value.

example output:

<tagName left="10.5" top="14.99" width="122.4" height="10.95">
See also
putRect

§ putDate()

void QXmlPut::putDate ( const QString &  tagName,
const QDate &  value 
)

Inserts a tag with name tagName which contains the QDate value.

example output:

<tagName>2012-04-03</tagName>
See also
putTime, putDateTime

§ putTime()

void QXmlPut::putTime ( const QString &  tagName,
const QTime &  value 
)

Inserts a tag with name tagName which contains the QTime value.

example output:

<tagName>09:50:27</tagName>
See also
putDate, putDateTime

§ putDateTime()

void QXmlPut::putDateTime ( const QString &  tagName,
const QDateTime &  value 
)

Inserts a tag with name tagName which contains the QDateTime value.

example output:

<tagName>2012-04-03T09:50:27</tagName>
See also
putDate, putTime

§ putByteArray()

void QXmlPut::putByteArray ( const QString &  tagName,
const QByteArray &  value,
int  blockWidth = 2048,
int  compression = 9 
)

Inserts a tag with name tagName which contains the QByteArray value.

The data of the QByteArray is saved in base-64. By setting compression to a number between 0 and 9, the data may be saved uncompressed to highly compressed. To improve handling with text editors, every blockWidth characters, a linebreak is inserted into the XML output.

example output:

<tagName compression="9"><![CDATA[AAAPmnjatVdrUFNnGoa6u7h1KZ261k4i4
oxbnN2t0B0I4SLEdqhgUXBXuVTCZU2rLi
cBjykBBUldRi2yR7brKlVAVFQkgYOEnnB
/tk/O+bHmeR87/fN9z==
]]></tagName>
See also
putImage

§ putImage()

void QXmlPut::putImage ( const QString &  tagName,
const QImage &  value,
const QString  format = QString("PNG"),
int  blockWidth = 2048 
)

Inserts a tag with name tagName which contains the QImage value.

The data of the QImage is saved in base-64. Compression is determined depending on the format, "JPEG" and "JPG" are saved uncompressed (because they are compressed already), all others are compressed. To improve handling with text editors, every blockWidth characters, a linebreak is inserted into the XML output.

Available formats typically are: BMP, GIF, JPG, JPEG, PNG, PBM, PGM, PPM, TIFF, XBM, XPM. (see QImageReader::supportedImageFormats())

example output:

<tagName format="PNG" compression="9"><![CDATA[AAAPmnjatVdrUFNnGoa6u7h1KZ261k4i4
oxbnN2t0B0I4SLEdqhgUXBXuVTCZU2rLi
cBjykBBUldRi2yR7brKlVAVFQkgYOEnnB
/tk/O+bHmeR87/fN9z==
]]></tagName>
See also
putImage

§ putPen()

void QXmlPut::putPen ( const QString &  tagName,
const QPen &  value 
)

Inserts a tag with name tagName which contains the QPen value.

example output:

<tagName width="2" joinstyle="0" capstyle="32" miterlimit="2" color="#5018ff" penstyle="3"/>
See also
putBrush, putFont

§ putBrush()

void QXmlPut::putBrush ( const QString &  tagName,
const QBrush &  value 
)

Inserts a tag with name tagName which contains the QBrush value.

example output:

<tagName brushstyle="14" color="#5018ff"/>
See also
putPen, putFont

§ putFont()

void QXmlPut::putFont ( const QString &  tagName,
const QFont &  value 
)

Inserts a tag with name tagName which contains the QFont value.

example output:

<tagName fontdescription="Monospace,24,-1,5,75,1,0,0,0,0"/>
See also
putPen, putBrush

§ saveWidget()

bool QXmlPut::saveWidget ( const QWidget *  value,
bool  warnWhenUnsupported = true 
)

Saves the state of the passed widget w inside the current parent xml tag. The xml data can later be loaded via the QXmlGet::loadWidget method, or any of the specialized widget loading methods such as QXmlGet::loadLineEdit or QXmlGet::loadSpinBox, etc.

If warnWhenUnsupported is set to true, a qDebug() output is issued when w is of an unsupported widget type.

Returns true if the widget was successfully saved to xml. Therefore it returns false if the widget is either unsupported or was not saved for other reasons (e.g. object name is empty).

Supported widget types are: QLineEdit, QAbstractButton (and subclasses such as QCheckBox and QRadioButton), QTextEdit, QPlainTextEdit, QSpinBox, QDoubleSpinBox, QComboBox, QAbstractSlider (and subclasses such as QScrollBar and QSlider), QDateTimeEdit (and subclasses such as QTimeEdit and QDateEdit), QFontComboBox, QGroupBox.

Note
For QComboBox, only the selected item is saved, and possibly the text value if the combo box is editable. If you wish to save all of the items themselves, see QXmlGet::loadComboBox.
See also
QXmlGet::loadWidget, saveWidgetsRecursive

§ saveWidgetsRecursive()

int QXmlPut::saveWidgetsRecursive ( const QWidget *  parent,
const QString &  prefix = "",
const QString &  suffix = "",
const QSet< const QWidget *> &  exclude = QSet<const QWidget*>() 
)

Saves the widget passed as parent to xml, as well as all direct and indirect child widgets that are supported by QXmlPutGet.

If prefix and/or suffix are provided, only widgets that have the according prefix and/or suffix in their object name are considered. This is useful for marking a specific subset of widgets for xml storage already during UI design. Further, any widgets specified in exclude are not considered.

Returns the number of widgets that were saved to xml.

See also
QXmlGet::loadWidgetsRecursive

§ saveLineEdit()

bool QXmlPut::saveLineEdit ( const QLineEdit *  value)

Saves the state of the passed QLineEdit w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadLineEdit method.

The line edit's text value is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadLineEdit, saveWidget

§ saveAbstractButton()

bool QXmlPut::saveAbstractButton ( const QAbstractButton *  value)

Saves the state of the passed QAbstractButton w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadAbstractButton method.

The button's checked state is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadAbstractButton, saveWidget

§ saveTextEdit()

bool QXmlPut::saveTextEdit ( const QTextEdit *  value)

Saves the state of the passed QTextEdit w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadTextEdit method.

The text edit's content is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadTextEdit, saveWidget

§ savePlainTextEdit()

bool QXmlPut::savePlainTextEdit ( const QPlainTextEdit *  value)

Saves the state of the passed QPlainTextEdit w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadPlainTextEdit method.

The text edit's content is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadPlainTextEdit, saveWidget

§ saveSpinBox()

bool QXmlPut::saveSpinBox ( const QSpinBox *  value)

Saves the state of the passed QSpinBox w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadSpinBox method.

The spin box value is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadSpinBox, saveWidget

§ saveDoubleSpinBox()

bool QXmlPut::saveDoubleSpinBox ( const QDoubleSpinBox *  value)

Saves the state of the passed QDoubleSpinBox w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadDoubleSpinBox method.

The spin box value is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadDoubleSpinBox, saveWidget

§ saveComboBox()

bool QXmlPut::saveComboBox ( const QComboBox *  value,
bool  items 
)

Saves the state of the passed QComboBox w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadComboBox method.

The combo box selection state/text is saved to the xml entry. If items is set to true, the items themselves are saved to the xml entry, too. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadComboBox, saveWidget

§ saveAbstractSlider()

bool QXmlPut::saveAbstractSlider ( const QAbstractSlider *  value)

Saves the state of the passed QAbstractSlider w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadAbstractSlider method.

The slider value is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadAbstractSlider, saveWidget

§ saveDateTimeEdit()

bool QXmlPut::saveDateTimeEdit ( const QDateTimeEdit *  value)

Saves the state of the passed QDateTimeEdit w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadDateTimeEdit method.

The edit's date/time is saved to the xml entry. Note that this method can also handle subclasses QDateEdit and QTimeEdit. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadDateTimeEdit, saveWidget

§ saveFontComboBox()

bool QXmlPut::saveFontComboBox ( const QFontComboBox *  value)

Saves the state of the passed QFontComboBox w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadFontComboBox method.

The font combo box selected font descriptor (usually only family, but potentially also size, weight, etc. if set) is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

See also
QXmlGet::loadFontComboBox, saveWidget

§ saveGroupBox()

bool QXmlPut::saveGroupBox ( const QGroupBox *  value)

Saves the state of the passed QGroupBox w under a dedicated tag inside the current parent xml tag. The xml data can later be retrieved via the corresponding QXmlGet::loadGroupBox method.

The group box checked state is saved to the xml entry. Returns false if the widget couldn't be saved (because it has an empty object name).

Consider using saveWidget as a more convenient alternative, since the type of the widget is inferred automatically.

Note
this method does not save the group box child widgets to the xml. To achieve this, use saveWidgetsRecursive instead.
See also
QXmlGet::loadGroupBox, saveWidget

§ restricted()

QXmlPut QXmlPut::restricted ( )

Returns a QXmlPut instance on the same Document and at the same position as this instance, but which is restricted to this hierarchy level (and the levels below). This means, the returned QXmlPut instance isn't allowed to rise above the current hierarchy level.

This is useful if you wish that subroutines can handle their own XML work without possibly interfering with the rest. By passing a restricted instance, it's guaranteed the subroutines don't accidentally write/read outside their designated XML element.

If only the subroutine needs to write to/read from a specific element, consider using descended.

example:

xmlPut.descend("toptag");
xmlPut.putString("exampleTag", "test");
writeOtherContent(xmlPut.restricted()); // A subroutine that writes to the <toptag> level
xmlPut.rise();
}
See also
descended

§ descend()

void QXmlPut::descend ( const QString &  tagName)

Creates a tag with the name tagName and descends into it. Child elements can then be created.

Once the work in the lower hierarchy level is done, you can return to the previous position in the parent hierarchy level by calling rise.

If a subroutine needs to write to/read from a specific element, consider using descended instead of a descend-rise-pair.

example:

xmlPut.descend("toptag");
xmlPut.putString("exampleTag", "test");
xmlPut.descend("subtag");
xmlPut.putInt("answer", 42);
xmlPut.rise();
xmlPut.rise();
See also
rise, descended

§ descended()

QXmlPut QXmlPut::descended ( const QString &  tagName)

Returns a QXmlPut instance that is descended into and restricted to the current element. Child elements can then be created with the returned instance normally via putString etc.

Due to the restriction, the returned instance can't rise above its initial hierarchy level, i.e. into or above the hierarchy level of the instance this function is called on.

When descending into elements like this, there is no need to call rise (and thus no possibility to forget a rise), because the current instance isn't influenced. Whatever descending/rising the subroutine does with the returned instance can't break the callers XML handling code.

example:

writeHeaderSubroutine(xmlPut.descended("header"));
writeBodySubroutine(xmlPut.descended("body"));
writeFooterSubroutine(xmlPut.descended("footer"));
See also
restricted, descend

§ rise()

bool QXmlPut::rise ( )

Rises to the previous position in the parent hierarchy level. This finishes the work in a lower hierarchy level that was started with descend earlier.

If a subroutine needs to write to/read from a specific element, consider using descended instead of a descend-rise-pair.

If this instance is restricted (see descended and restricted) and is already inside its highest allowed hierarchy level, a further attempt to rise will return false without changing the current hierarchy level, and cause a corresponding qDebug output.

example:

xmlPut.descend("toptag");
xmlPut.putString("exampleTag", "test");
xmlPut.descend("subtag");
xmlPut.putInt("answer", 42);
xmlPut.rise();
xmlPut.rise();
See also
descend

§ goTo()

bool QXmlPut::goTo ( QDomElement  parentElement)

Changes the current parent element to parentElement. It must be in the current QDomDocument already.

If this instance is restricted (see descended and restricted) and parentElement is not inside the allowed hierarchy, this function will return false without changing the current position, and cause a corresponding qDebug output.

You probably won't use this function very often, since normal, linear QXmlPutGet navigation should be done with descend, rise, descended, etc. However, it's useful for nonlinear XML navigation, where frequent jumps between different locations in the XML hierarchy need to be done.

See also
element

§ element()

QDomElement QXmlPut::element ( ) const
inline

Returns the current element as a QDomElement. This can be used as a jump target for goTo, or some low-level manipulation of the node with the Qt-DOM-interface.

§ setAttributeString()

void QXmlPut::setAttributeString ( const QString &  name,
const QString &  value 
)

Adds an attribute with name to the current element. The attribute will carry the string value.

example output:

<tagName name="example string"/>

§ setAttributeInt()

void QXmlPut::setAttributeInt ( const QString &  name,
int  value 
)

Adds an attribute with name to the current element. The attribute will carry the int value.

example output:

<tagName name="2"/>

§ setAttributeIntVector()

void QXmlPut::setAttributeIntVector ( const QString &  name,
const QVector< int > &  value 
)

Adds an attribute with name to the current element. The attribute will carry the int vector value.

example output:

<tagName name="2;4;6;8;10"/>

§ setAttributeDouble()

void QXmlPut::setAttributeDouble ( const QString &  name,
double  value,
char  format = 'g',
int  precision = 15 
)

Adds an attribute with name to the current element. The attribute will carry the double value.

example output:

<tagName name="3.623"/>

§ setAttributeDoubleVector()

void QXmlPut::setAttributeDoubleVector ( const QString &  name,
const QVector< double > &  value,
char  format = 'g',
int  precision = 15 
)

Adds an attribute with name to the current element. The attribute will carry the double vector value.

example output:

<tagName name="3.6;4.2;9.9"/>

§ setAttributeBool()

void QXmlPut::setAttributeBool ( const QString &  name,
bool  value,
QXmlPutGet::BoolFormat  format = QXmlPutGet::bfYesNo 
)

Adds an attribute with name to the current element. The attribute will carry the bool value.

Depending on the specified format (see QXmlPutGet::BoolFormat), the boolean value is represented with different strings.

example output:

<tagName name="no"/>

§ setAttributeBoolVector()

void QXmlPut::setAttributeBoolVector ( const QString &  name,
const QVector< bool > &  value,
QXmlPutGet::BoolFormat  format = QXmlPutGet::bfYesNo 
)

Adds an attribute with name to the current element. The attribute will carry the bool vector value.

Depending on the specified format (see QXmlPutGet::BoolFormat), the boolean value is represented with different strings.

example output:

<tagName name="no;yes;yes;no;yes"/>

§ setAttributeColor()

void QXmlPut::setAttributeColor ( const QString &  name,
const QColor &  value 
)

Adds an attribute with name to the current element. The attribute will carry the QColor value.

If the color contains no transparency component (i.e. alpha is 255), the color is saved in the format "#rrggbb". If it contains alpha, it is saved as "#rrggbbaa".

example output:

<tagName name="#83A0FF"/>

§ toString()

QString QXmlPut::toString ( int  spacesPerIndent = 2) const

Returns the XML document as a string. Sub-elements are indented by spacesPerIndent spaces.

See also
QXmlGet::fromString

§ save()

bool QXmlPut::save ( const QString &  fileName,
int  spacesPerIndent = 2 
) const

Saves the XML document to the file fileName. Sub-elements are indented by spacesPerIndent spaces.

The encoding (typically UTF-8) specified in the XML declaration (QXmlPut constructor) is used.

This function returns false if the file couldn't be created/written to.

See also
QXmlGet::load

The documentation for this class was generated from the following files: