Main Page · All Classes ·
Public Functions
QXmlGet Class Reference

Is used to load and read from the XML document. More...

Public Functions

 QXmlGet ()
 
 QXmlGet (QDomDocument document)
 
 QXmlGet (const QXmlPut &xmlPut)
 
QDomDocument document () const
 
QString docType () const
 
QString publicId () const
 
QString systemId () const
 
QString xmlDeclaration () const
 
QString xmlVersion () const
 
QString encoding () const
 
bool standalone () const
 
bool find (const QString &tagName)
 
bool findAndDescend (const QString &tagName)
 
void findReset ()
 
bool findNext (const QString &tagName=QString())
 
bool findNextAndDescend (const QString &tagName=QString())
 
int childCount (const QString &tagName=QString()) const
 
bool hasChildren () const
 
QString tagName () const
 
QString getString (const QString &defaultValue=QString()) const
 
QStringList getStringList (const QStringList &defaultValue=QStringList())
 
int getInt (int defaultValue=0) const
 
QVector< int > getIntVector (const QVector< int > &defaultValue=QVector< int >()) const
 
double getDouble (double defaultValue=0) const
 
QVector< double > getDoubleVector (const QVector< double > &defaultValue=QVector< double >()) const
 
bool getBool (bool defaultValue=false, QXmlPutGet::BoolFormats formats=QXmlPutGet::bfAll) const
 
QVector< bool > getBoolVector (const QVector< bool > &defaultValue=QVector< bool >(), QXmlPutGet::BoolFormats formats=QXmlPutGet::bfAll) const
 
QColor getColor (const QColor &defaultValue=QColor()) const
 
QSize getSize (const QSize &defaultValue=QSize()) const
 
QSizeF getSizeF (const QSizeF &defaultValue=QSizeF()) const
 
QPoint getPoint (const QPoint &defaultValue=QPoint()) const
 
QPointF getPointF (const QPointF &defaultValue=QPointF()) const
 
QRect getRect (const QRect &defaultValue=QRect()) const
 
QRectF getRectF (const QRectF &defaultValue=QRectF()) const
 
QDate getDate (const QDate &defaultValue=QDate()) const
 
QTime getTime (const QTime &defaultValue=QTime()) const
 
QDateTime getDateTime (const QDateTime &defaultValue=QDateTime()) const
 
QByteArray getByteArray (const QByteArray &defaultValue=QByteArray()) const
 
QImage getImage (const QImage &defaultValue=QImage()) const
 
QPen getPen (const QPen &defaultValue=QPen()) const
 
QBrush getBrush (const QBrush &defaultValue=QBrush()) const
 
QFont getFont (const QFont &defaultValue=QFont()) const
 
bool loadWidget (QWidget *w, bool warnWhenUnsupported=true)
 
bool loadWidgetsRecursive (QWidget *parent, const QString &prefix="", const QString &suffix="", const QSet< const QWidget *> &exclude=QSet< const QWidget *>())
 
bool loadLineEdit (QLineEdit *w)
 
bool loadAbstractButton (QAbstractButton *w)
 
bool loadTextEdit (QTextEdit *w)
 
bool loadPlainTextEdit (QPlainTextEdit *w)
 
bool loadSpinBox (QSpinBox *w)
 
bool loadDoubleSpinBox (QDoubleSpinBox *w)
 
bool loadComboBox (QComboBox *w, bool items)
 
bool loadAbstractSlider (QAbstractSlider *w)
 
bool loadDateTimeEdit (QDateTimeEdit *w)
 
bool loadFontComboBox (QFontComboBox *w)
 
bool loadGroupBox (QGroupBox *w)
 
bool hasAttribute (const QString &name) const
 
QString getAttributeString (const QString &name, const QString &defaultValue=QString()) const
 
int getAttributeInt (const QString &name, int defaultValue=0) const
 
QVector< int > getAttributeIntVector (const QString &name, const QVector< int > &defaultValue=QVector< int >()) const
 
double getAttributeDouble (const QString &name, double defaultValue=0) const
 
QVector< double > getAttributeDoubleVector (const QString &name, const QVector< double > &defaultValue=QVector< double >()) const
 
bool getAttributeBool (const QString &name, bool defaultValue=false, QXmlPutGet::BoolFormats formats=QXmlPutGet::bfAll) const
 
QVector< bool > getAttributeBoolVector (const QString &name, const QVector< bool > &defaultValue=QVector< bool >(), QXmlPutGet::BoolFormats format=QXmlPutGet::bfAll) const
 
QColor getAttributeColor (const QString &name, const QColor &defaultValue=QColor()) const
 
bool fromString (const QString &str, QString *errorMessage=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr)
 
bool load (const QString &fileName, QString *errorMessage=nullptr, int *errorLine=nullptr, int *errorColumn=nullptr)
 
QXmlGet restricted ()
 
void descend ()
 
QXmlGet descended ()
 
bool rise ()
 
bool goTo (QDomElement parentElement)
 
QDomElement element () const
 

Detailed Description

Is used to load and read from the XML document.

Constructor & Destructor Documentation

§ QXmlGet() [1/3]

QXmlGet::QXmlGet ( )

Creates a QXmlGet instance with an empty document. Call fromString or load to conveniently load XML content to the document. If you have a QDomDocument ready, use the ructor instead.

§ QXmlGet() [2/3]

QXmlGet::QXmlGet ( QDomDocument  document)

This is an overloaded function.

Creates a QXmlGet instance from the passed QDomDocument. This instance can then read from the document.

§ QXmlGet() [3/3]

QXmlGet::QXmlGet ( const QXmlPut xmlPut)

This is an overloaded function.

Creates a QXmlGet instance from the QXmlPut instance xmlPut. This way you may now read from the document, to which the QXmlPut instance writes.

Member Function Documentation

§ document()

QDomDocument QXmlGet::document ( ) const
inline

Returns the QDomDocument this QXmlGet instance is using.

§ docType()

QString QXmlGet::docType ( ) const

Returns the doctype name.

example:

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

has the doctype "myDocType".

§ publicId()

QString QXmlGet::publicId ( ) const

Returns the public identifier of the external DTD subset or an empty string if there is no public identifier.

example:

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

has the public identifier "myPublicId".

§ systemId()

QString QXmlGet::systemId ( ) const

Returns the system identifier of the external DTD subset or an empty string if there is no system identifier.

example:

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

has the system identifier "mySystemId".

§ xmlDeclaration()

QString QXmlGet::xmlDeclaration ( ) const
inline

Returns the XML-Declaration (the tag name of the <? .. ?> header), which always is "xml".

(Thus this function is rather redundant, but the DOM provides it, so it is provided here, too.)

§ xmlVersion()

QString QXmlGet::xmlVersion ( ) const
inline

Returns the xml version of the document. Typically this is "1.0" or "1.1".

example:

<?xml version="1.0" encoding="UTF-8"?>
(...)

§ encoding()

QString QXmlGet::encoding ( ) const
inline

Returns the encoding of the document, e.g. "UTF-8".

example:

<?xml version="1.0" encoding="UTF-8"?>
(...)

§ standalone()

bool QXmlGet::standalone ( ) const
inline

Returns the standalone-property of the document's xml declaration.

example:

<?xml version="1.0" encoding="UTF-8"?>

has standalone false

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

has standalone true.

§ find()

bool QXmlGet::find ( const QString &  tagName)

Finds the first element named tagName in the current hierarchy level. If this returns true, an element was found. You then can access contents and attributes of this element via the get(...) functions.

For example, if you expect the element to contain a string as in

<element>Hellothere!</element>

call getString to retrieve "Hello there!".

If you expect the element to have further child elements and want to descend into their hierarchy level, call descend or descended.

If you expect more than one element with the name tagName in the current hierarchy level, consider using findNext instead, because find would always just find the first element.

See also
findNext, findAndDescend, findNextAndDescend, findReset

§ findAndDescend()

bool QXmlGet::findAndDescend ( const QString &  tagName)

Finds the first element with the specified tagName in the current hierarchy level and (if found) descends into it. If such an element is found, the function returns true. In that case you must make sure to call rise after the work in the lower hierarchy level is done.

If you expect more than one element with the name tagName in the current hierarchy level, consider using findNextAndDescend instead, because findAndDescend would always just find the first element.

See also
findNextAndDescend, find, descend, descended

§ findReset()

void QXmlGet::findReset ( )

Resets the current element to the starting position (this means it will be pointing to the parent of the current hierarchy level). Any subsequent call to findNext or findNextAndDescend would start searching from the beginning. Calls to find are not affected, since it always starts searching from the beginning.

See also
findNext, findNextAndDescend, find

§ findNext()

bool QXmlGet::findNext ( const QString &  tagName = QString())

finds the next element after the current element with tag name tagName.

Returns true when an element was found. This makes it possible to use it directly as a condition of a while-loop, looping over all elements with name tagName. If you want to descend into every such element, consider using findNextAndDescend.

Once no next element was found, the function returns false and the current element is reset. This means a subsequent call would restart the loop from the beginning, for example searching for a different tagName.

See also
findReset, findNextAndDescend, find

§ findNextAndDescend()

bool QXmlGet::findNextAndDescend ( const QString &  tagName = QString())

finds the next element after the current element with tag name tagName and descends into it.

Returns true when an element was found. This makes it possible to use it directly as a condition of a while-loop, looping over (and descending into) all elements with name tagName. Don't forget to call rise at the end of each iteration.

Once no next element was found, the function returns false and the current element is reset. This means a subsequent call would restart the loop from the beginning, for example searching for a different tagName.

See also
findNext, findReset, find

§ childCount()

int QXmlGet::childCount ( const QString &  tagName = QString()) const

Returns the number of elements with the specified tag name inside the current element. If tagName is empty, all elements are counted.

See also
hasChildren

§ hasChildren()

bool QXmlGet::hasChildren ( ) const

Returns whether the current element has children (sub elements). If so, you can call descend or descended to change into their hierarchy level to access them.

See also
childCount

§ tagName()

QString QXmlGet::tagName ( ) const

Returns the tag name of the current element.

For example, the element

<rect width="4">

has the tag name "rect".

§ getString()

QString QXmlGet::getString ( const QString &  defaultValue = QString()) const

Returns the string the current tag contains. If the current tag doesn't contain a string, defaultValue is returned.

See also
getStringList

§ getStringList()

QStringList QXmlGet::getStringList ( const QStringList &  defaultValue = QStringList())

Returns the string list the current tag contains. If the current tag doesn't contain a string list, defaultValue is returned.

See also
getString

§ getInt()

int QXmlGet::getInt ( int  defaultValue = 0) const

Returns the integer the current tag contains. If the current tag doesn't contain an integer, defaultValue is returned.

See also
getIntVector

§ getIntVector()

QVector< int > QXmlGet::getIntVector ( const QVector< int > &  defaultValue = QVector<int>()) const

Returns the integer vector the current tag contains. If the current tag doesn't contain an integer vector, defaultValue is returned.

See also
getInt

§ getDouble()

double QXmlGet::getDouble ( double  defaultValue = 0) const

Returns the double the current tag contains. If the current tag doesn't contain a double, defaultValue is returned.

See also
getDoubleVector

§ getDoubleVector()

QVector< double > QXmlGet::getDoubleVector ( const QVector< double > &  defaultValue = QVector<double>()) const

Returns the double vector the current tag contains. If the current tag doesn't contain a double vector, defaultValue is returned.

See also
getDouble

§ getBool()

bool QXmlGet::getBool ( bool  defaultValue = false,
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool the current tag contains. If the current tag doesn't contain a bool, defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also
getBoolVector, QXmlPutGet::BoolFormat

§ getBoolVector()

QVector< bool > QXmlGet::getBoolVector ( const QVector< bool > &  defaultValue = QVector<bool>(),
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool vector the current tag contains. If the current tag doesn't contain a bool vector, defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also
getBool, QXmlPutGet::BoolFormat

§ getColor()

QColor QXmlGet::getColor ( const QColor &  defaultValue = QColor()) const

Returns the QColor the current tag contains. If the current tag doesn't contain a QColor, defaultValue is returned.

§ getSize()

QSize QXmlGet::getSize ( const QSize &  defaultValue = QSize()) const

Returns the QSize the current tag contains. If the current tag doesn't contain a QSize, defaultValue is returned.

See also
getSizeF

§ getSizeF()

QSizeF QXmlGet::getSizeF ( const QSizeF &  defaultValue = QSizeF()) const

Returns the QSizeF the current tag contains. If the current tag doesn't contain a QSizeF, defaultValue is returned.

See also
getSize

§ getPoint()

QPoint QXmlGet::getPoint ( const QPoint &  defaultValue = QPoint()) const

Returns the QPoint the current tag contains. If the current tag doesn't contain a QPoint, defaultValue is returned.

See also
getPointF

§ getPointF()

QPointF QXmlGet::getPointF ( const QPointF &  defaultValue = QPointF()) const

Returns the QPointF the current tag contains. If the current tag doesn't contain a QPointF, defaultValue is returned.

See also
getPoint

§ getRect()

QRect QXmlGet::getRect ( const QRect &  defaultValue = QRect()) const

Returns the QRect the current tag contains. If the current tag doesn't contain a QRect, defaultValue is returned.

See also
getRectF

§ getRectF()

QRectF QXmlGet::getRectF ( const QRectF &  defaultValue = QRectF()) const

Returns the QRectF the current tag contains. If the current tag doesn't contain a QRectF, defaultValue is returned.

See also
getRect

§ getDate()

QDate QXmlGet::getDate ( const QDate &  defaultValue = QDate()) const

Returns the QDate the current tag contains. If the current tag doesn't contain a QDate, defaultValue is returned.

See also
getDateTime, getTime

§ getTime()

QTime QXmlGet::getTime ( const QTime &  defaultValue = QTime()) const

Returns the QTime the current tag contains. If the current tag doesn't contain a QTime, defaultValue is returned.

See also
getDateTime, getDate

§ getDateTime()

QDateTime QXmlGet::getDateTime ( const QDateTime &  defaultValue = QDateTime()) const

Returns the QDateTime the current tag contains. If the current tag doesn't contain a QDateTime, defaultValue is returned.

See also
getTime, getDate

§ getByteArray()

QByteArray QXmlGet::getByteArray ( const QByteArray &  defaultValue = QByteArray()) const

Returns the QByteArray the current tag contains. If the current tag doesn't contain a QByteArray, defaultValue is returned.

§ getImage()

QImage QXmlGet::getImage ( const QImage &  defaultValue = QImage()) const

Returns the QImage the current tag contains. If the current tag doesn't contain a QImage, defaultValue is returned.

§ getPen()

QPen QXmlGet::getPen ( const QPen &  defaultValue = QPen()) const

Returns the QPen the current tag contains. If the current tag doesn't contain a QPen, defaultValue is returned.

See also
getBrush

§ getBrush()

QBrush QXmlGet::getBrush ( const QBrush &  defaultValue = QBrush()) const

Returns the QBrush the current tag contains. If the current tag doesn't contain a QBrush, defaultValue is returned.

See also
getPen

§ getFont()

QFont QXmlGet::getFont ( const QFont &  defaultValue = QFont()) const

Returns the QFont the current tag contains. If the current tag doesn't contain a QFont, defaultValue is returned.

§ loadWidget()

bool QXmlGet::loadWidget ( QWidget *  w,
bool  warnWhenUnsupported = true 
)

Loads the state of the passed widget w from anywhere inside the current parent xml tag. The xml data must have previously been created via the QXmlPut::saveWidget method, or any of the specialized widget saving methods such as QXmlPut::saveLineEdit or QXmlPut::saveSpinBox, etc.

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

Returns false if the widget w is a supported widget but couldn't be found/loaded under this xml tag. Therefore it returns true if the widget was either loaded successfully or it is an unsupported widget. This behavior allows successively calling loadWidget on a group of widgets possibly containing unsupported widgets and only catching load errors if the widget should in principle be available in the xml (see loadWidgetsRecursive).

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 restored, and possibly the text value if the combo box is editable. If you wish to retrieve all of the items themselves, see loadComboBox.
See also
QXmlPut::saveWidget, loadWidgetsRecursive

§ loadWidgetsRecursive()

bool QXmlGet::loadWidgetsRecursive ( QWidget *  parent,
const QString &  prefix = "",
const QString &  suffix = "",
const QSet< const QWidget *> &  exclude = QSet<const QWidget*>() 
)

Loads the widget passed as parent from 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 whether all widgets were loaded successfully. If false is returned, at least one widget that should have been saved with an according call to QXmlPut::saveWidgetsRecursive (with the same parameters) couldn't be found/loaded.

See also
QXmlPut::saveWidgetsRecursive

§ loadLineEdit()

bool QXmlGet::loadLineEdit ( QLineEdit *  w)

Loads the state of the passed QLineEdit w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveLineEdit method.

The line edit's text value is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::saveLineEdit, loadWidget

§ loadAbstractButton()

bool QXmlGet::loadAbstractButton ( QAbstractButton *  w)

Loads the state of the passed QAbstractButton w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveAbstractButton method.

The button's checked state is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::saveAbstractButton, loadWidget

§ loadTextEdit()

bool QXmlGet::loadTextEdit ( QTextEdit *  w)

Loads the state of the passed QTextEdit w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveTextEdit method.

The text edit's content is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::saveTextEdit, loadWidget

§ loadPlainTextEdit()

bool QXmlGet::loadPlainTextEdit ( QPlainTextEdit *  w)

Loads the state of the passed QPlainTextEdit w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::savePlainTextEdit method.

The text edit's content is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::savePlainTextEdit, loadWidget

§ loadSpinBox()

bool QXmlGet::loadSpinBox ( QSpinBox *  w)

Loads the state of the passed QSpinBox w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveSpinBox method.

The spin box value is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::saveSpinBox, loadWidget

§ loadDoubleSpinBox()

bool QXmlGet::loadDoubleSpinBox ( QDoubleSpinBox *  w)

Loads the state of the passed QDoubleSpinBox w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveDoubleSpinBox method.

The spin box value is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::saveDoubleSpinBox, loadWidget

§ loadComboBox()

bool QXmlGet::loadComboBox ( QComboBox *  w,
bool  items 
)

Loads the state of the passed QComboBox w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveComboBox method.

The combo box selection state/text is retrieved from the xml entry. If items is set to true, the items themselves are retrieved from the xml entry, too. Returns true if loading was successful.

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

See also
QXmlPut::saveComboBox, loadWidget

§ loadAbstractSlider()

bool QXmlGet::loadAbstractSlider ( QAbstractSlider *  w)

Loads the state of the passed QAbstractSlider w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveAbstractSlider method.

The slider value is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::saveAbstractSlider, loadWidget

§ loadDateTimeEdit()

bool QXmlGet::loadDateTimeEdit ( QDateTimeEdit *  w)

Loads the state of the passed QDateTimeEdit w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveDateTimeEdit method.

The edit's date/time is retrieved from the xml entry. Note that this method can also handle subclasses QDateEdit and QTimeEdit. Returns true if loading was successful.

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

See also
QXmlPut::saveDateTimeEdit, loadWidget

§ loadFontComboBox()

bool QXmlGet::loadFontComboBox ( QFontComboBox *  w)

Loads the state of the passed QFontComboBox w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveFontComboBox method.

The font combo box selected font descriptor (family, size, weight, etc.) is retrieved from the xml entry. Returns true if loading was successful.

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

See also
QXmlPut::saveFontComboBox, loadWidget

§ loadGroupBox()

bool QXmlGet::loadGroupBox ( QGroupBox *  w)

Loads the state of the passed QGroupBox w from anywhere inside the current parent xml tag. The xml data must have previously been created via the corresponding QXmlPut::saveGroupBox method.

If the group box is checkable, its checked state is retrieved from the xml entry. Returns true if loading was successful.

Consider using loadWidget 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.
See also
QXmlPut::saveGroupBox, loadWidget

§ hasAttribute()

bool QXmlGet::hasAttribute ( const QString &  name) const

Returns whether the current tag has an attribute with the name name.

§ getAttributeString()

QString QXmlGet::getAttributeString ( const QString &  name,
const QString &  defaultValue = QString() 
) const

Returns the string the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

§ getAttributeInt()

int QXmlGet::getAttributeInt ( const QString &  name,
int  defaultValue = 0 
) const

Returns the integer the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also
getAttributeIntVector

§ getAttributeIntVector()

QVector< int > QXmlGet::getAttributeIntVector ( const QString &  name,
const QVector< int > &  defaultValue = QVector<int>() 
) const

Returns the integer vector the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also
getAttributeInt

§ getAttributeDouble()

double QXmlGet::getAttributeDouble ( const QString &  name,
double  defaultValue = 0 
) const

Returns the double the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also
getAttributeDoubleVector

§ getAttributeDoubleVector()

QVector< double > QXmlGet::getAttributeDoubleVector ( const QString &  name,
const QVector< double > &  defaultValue = QVector<double>() 
) const

Returns the double vector the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

See also
getAttributeDouble

§ getAttributeBool()

bool QXmlGet::getAttributeBool ( const QString &  name,
bool  defaultValue = false,
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also
getAttributeBoolVector

§ getAttributeBoolVector()

QVector< bool > QXmlGet::getAttributeBoolVector ( const QString &  name,
const QVector< bool > &  defaultValue = QVector<bool>(),
QXmlPutGet::BoolFormats  formats = QXmlPutGet::bfAll 
) const

Returns the bool vector the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

by setting formats, you may specify which boolean formats this function accepts.

See also
getAttributeBool

§ getAttributeColor()

QColor QXmlGet::getAttributeColor ( const QString &  name,
const QColor &  defaultValue = QColor() 
) const

Returns the QColor the current tag carries as attribute with the name name. If the current tag doesn't contain such an attribute,defaultValue is returned.

§ fromString()

bool QXmlGet::fromString ( const QString &  str,
QString *  errorMessage = nullptr,
int *  errorLine = nullptr,
int *  errorColumn = nullptr 
)

Loads the XML content from the string str into this QXmlGet instance. Returns true on success.

If the provided markup contains errors, this function returns false and outputs the error message in errorMessage and the location of the error in errorLine and errorColumn.

See also
QXmlPut::toString

§ load()

bool QXmlGet::load ( const QString &  fileName,
QString *  errorMessage = nullptr,
int *  errorLine = nullptr,
int *  errorColumn = nullptr 
)

Loads the XML content from the file fileName into this QXmlGet instance. Returns true on success.

If the provided markup contains errors, this function returns false and outputs the error message in errorMessage and the location of the error in errorLine and errorColumn.

If the provided file can't be opened (e.g. because it doesn't exist or the application doesn't have read permission), this function returns false and errorMessage, errorLine and errorColumn are left unchanged.

See also
QXmlPut::save

§ restricted()

QXmlGet QXmlGet::restricted ( )

Returns a QXmlGet 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 QXmlGet 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:

if (xmlGet.find("toptag")) // we might have better used findAndDescend() here.
{
xmlGet.descend();
if (xmlGet.find("stringtag"))
QString str = xmlGet.getString();
readOtherContent(xmlGet.restricted()); // A subroutine that reads from the <toptag> level
xmlGet.rise();
}
See also
descended

§ descend()

void QXmlGet::descend ( )

Descends into the current element. Child elements can then be accessed normally via find etc.

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:

if (xmlGet.find("firsttag")) // we might have better used findAndDescend() here.
{
xmlGet.descend(); // descend into the <firsttag> element, it is now the parent element.
if (xmlGet.find("stringtag"))
QString str = xmlGet.getString();
xmlGet.rise(); // rise from the <firsttag> element. <firsttag> is now the current element again, and not the parent element anymore.
}
See also
rise, descended, findAndDescend, findNextAndDescend

§ descended()

QXmlGet QXmlGet::descended ( )

Returns a QXmlGet instance that is descended into and restricted to the current element. Child elements can then be accessed with the returned instance normally via find 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:

if (xmlGet.find("header"))
readHeaderSubroutine(xmlGet.descended());
if (xmlGet.find("body"))
readBodySubroutine(xmlGet.descended());
if (xmlGet.find("footer"))
readFooterSubroutine(xmlGet.descended());
See also
restricted, descend

§ rise()

bool QXmlGet::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:

if (xmlGet.find("firsttag")) // we might have better used findAndDescend() here.
{
xmlGet.descend(); // descend into the <firsttag> element, it is now the parent element.
if (xmlGet.find("stringtag"))
QString str = xmlGet.getString();
xmlGet.rise(); // rise from the <firsttag> element. <firsttag> is now the current element again, and not the parent element anymore.
}
See also
descend

§ goTo()

bool QXmlGet::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 find, 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 QXmlGet::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.


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