Qt 4.8
Public Functions | Properties | Friends | List of all members
QXmlResultItems Class Reference

The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery. More...

#include <qxmlresultitems.h>

Public Functions

QXmlItem current () const
 Returns the current item. More...
 
bool hasError () const
 If an error occurred during evaluation of the query, true is returned. More...
 
QXmlItem next ()
 Returns the next result in the sequence produced by lazy evaluation of the associated query. More...
 
 QXmlResultItems ()
 Constructs an instance of QXmlResultItems. More...
 
virtual ~QXmlResultItems ()
 Destroys this instance of QXmlResultItems. More...
 

Properties

QScopedPointer< QXmlResultItemsPrivated_ptr
 

Friends

class QXmlQuery
 

Detailed Description

The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery.

Note
This class or function is reentrant.
Since
4.4

QXmlResultItems presents the evaluation of an associated query as a sequence of QXmlItems. The sequence is traversed by repeatedly calling next(), which actually produces the sequence by lazy evaluation of the query.

QXmlQuery query;
query.setQuery("<e/>, 1, 'two'");
if (query.isValid()) {
query.evaluateTo(&result);
QXmlItem item(result.next());
while (!item.isNull()) {
// use item
item = result.next();
}
if (result.hasError())
/* Runtime error! */;
}

An effect of letting next() produce the sequence by lazy evaluation is that a query error can occur on any call to next(). If an error occurs, both next() and current() will return the null QXmlItem, and hasError() will return true.

QXmlResultItems can be thought of as an "iterator" that traverses the sequence of query results once, in the forward direction. Each call to next() advances the iterator to the next QXmlItem in the sequence and returns it, and current() always returns the QXmlItem that next() returned the last time it was called.

Note
When using the QXmlResultItems overload of QXmlQuery::evaluateTo() to execute a query, it is advisable to create a new instance of this class for each new set of results rather than reusing an old instance.
See also
QXmlItem::isNode(), QXmlItem::isAtomicValue(), QXmlNodeModelIndex

Definition at line 57 of file qxmlresultitems.h.

Constructors and Destructors

◆ QXmlResultItems()

QXmlResultItems::QXmlResultItems ( )

Constructs an instance of QXmlResultItems.

Definition at line 86 of file qxmlresultitems.cpp.

87 {
88 }
QScopedPointer< QXmlResultItemsPrivate > d_ptr

◆ ~QXmlResultItems()

QXmlResultItems::~QXmlResultItems ( )
virtual

Destroys this instance of QXmlResultItems.

Definition at line 93 of file qxmlresultitems.cpp.

94 {
95 }

Functions

◆ current()

QXmlItem QXmlResultItems::current ( ) const

Returns the current item.

The current item is the last item that was produced and returned by next().

Returns a null QXmlItem if there is no associated QXmlQuery.

Definition at line 131 of file qxmlresultitems.cpp.

132 {
133  Q_D(const QXmlResultItems);
134 
135  if(d->hasError)
136  return QXmlItem();
137  else
138  return d->current;
139 }
double d
Definition: qnumeric_p.h:62
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
The QXmlItem class contains either an XML node or an atomic value.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ hasError()

bool QXmlResultItems::hasError ( ) const

If an error occurred during evaluation of the query, true is returned.

Returns false if query evaluation has been done.

Definition at line 148 of file qxmlresultitems.cpp.

149 {
150  Q_D(const QXmlResultItems);
151  return d->hasError;
152 }
double d
Definition: qnumeric_p.h:62
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ next()

QXmlItem QXmlResultItems::next ( )

Returns the next result in the sequence produced by lazy evaluation of the associated query.

When the returned QXmlItem is null, either the evaluation terminated normally without producing another result, or an error occurred. Call hasError() to determine whether the null item was caused by normal termination or by an error.

Returns a null QXmlItem if there is no associated QXmlQuery.

Definition at line 106 of file qxmlresultitems.cpp.

Referenced by QDeclarativeXmlQueryEngine::doQueryJob(), QDeclarativeXmlQueryEngine::doSubQueryJob(), and QDeclarativeXmlQueryEngine::getValuesOfKeyRoles().

107 {
109  if(d->hasError)
110  return QXmlItem();
111 
112  try
113  {
114  d->current = QPatternist::Item::toPublic(d->iterator->next());
115  return d->current;
116  }
117  catch(const QPatternist::Exception)
118  {
119  d->current = QXmlItem();
120  d->hasError = true;
121  return QXmlItem();
122  }
123 }
double d
Definition: qnumeric_p.h:62
The QXmlResultItems class iterates through the results of evaluating an XQuery in QXmlQuery...
The QXmlItem class contains either an XML node or an atomic value.
#define Q_D(Class)
Definition: qglobal.h:2482
static QXmlItem toPublic(const Item &i)
Definition: qitem_p.h:417

Friends and Related Functions

◆ QXmlQuery

friend class QXmlQuery
friend

Definition at line 68 of file qxmlresultitems.h.

Properties

◆ d_ptr

QScopedPointer<QXmlResultItemsPrivate> QXmlResultItems::d_ptr
private

Definition at line 70 of file qxmlresultitems.h.

Referenced by QXmlQuery::evaluateTo().


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