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

The QDeclarativeDomDocument class represents the root of a QML document. More...

#include <qdeclarativedom_p.h>

Public Functions

QList< QDeclarativeErrorerrors () const
 Returns the last load errors. More...
 
QList< QDeclarativeDomImportimports () const
 Returns all import statements in qml. More...
 
bool load (QDeclarativeEngine *, const QByteArray &, const QUrl &=QUrl())
 Loads a QDeclarativeDomDocument from data. More...
 
QDeclarativeDomDocumentoperator= (const QDeclarativeDomDocument &)
 Assign other to this QDeclarativeDomDocument. More...
 
 QDeclarativeDomDocument ()
 Construct an empty QDeclarativeDomDocument. More...
 
 QDeclarativeDomDocument (const QDeclarativeDomDocument &)
 Create a copy of other QDeclarativeDomDocument. More...
 
QDeclarativeDomObject rootObject () const
 Returns the document's root object, or an invalid QDeclarativeDomObject if the document has no root. More...
 
 ~QDeclarativeDomDocument ()
 Destroy the QDeclarativeDomDocument. More...
 

Properties

QSharedDataPointer< QDeclarativeDomDocumentPrivated
 

Detailed Description

The QDeclarativeDomDocument class represents the root of a QML document.

Warning
This function is not part of the public interface.

A QML document is a self-contained snippet of QML, usually contained in a single file. Each document has a root object, accessible through QDeclarativeDomDocument::rootObject().

The QDeclarativeDomDocument class allows the programmer to inspect a QML document by calling QDeclarativeDomDocument::load().

The following example loads a QML file from disk, and prints out its root object type and the properties assigned in the root object.

QFile file(inputFileName);
QByteArray xmlData = file.readAll();
document.load(qmlengine, xmlData);
qDebug() << rootObject.objectType();
qDebug() << property.propertyName();

Definition at line 81 of file qdeclarativedom_p.h.

Constructors and Destructors

◆ QDeclarativeDomDocument() [1/2]

QDeclarativeDomDocument::QDeclarativeDomDocument ( )

Construct an empty QDeclarativeDomDocument.

Definition at line 101 of file qdeclarativedom.cpp.

103 {
104 }
QSharedDataPointer< QDeclarativeDomDocumentPrivate > d

◆ QDeclarativeDomDocument() [2/2]

QDeclarativeDomDocument::QDeclarativeDomDocument ( const QDeclarativeDomDocument other)

Create a copy of other QDeclarativeDomDocument.

Definition at line 109 of file qdeclarativedom.cpp.

110 : d(other.d)
111 {
112 }
QSharedDataPointer< QDeclarativeDomDocumentPrivate > d

◆ ~QDeclarativeDomDocument()

QDeclarativeDomDocument::~QDeclarativeDomDocument ( )

Destroy the QDeclarativeDomDocument.

Definition at line 117 of file qdeclarativedom.cpp.

118 {
119 }

Functions

◆ errors()

QList< QDeclarativeError > QDeclarativeDomDocument::errors ( ) const

Returns the last load errors.

The load errors will be reset after a successful call to load().

See also
load()

Definition at line 190 of file qdeclarativedom.cpp.

191 {
192  return d->errors;
193 }
QList< QDeclarativeError > errors
QSharedDataPointer< QDeclarativeDomDocumentPrivate > d

◆ imports()

QList< QDeclarativeDomImport > QDeclarativeDomDocument::imports ( ) const

Returns all import statements in qml.

Definition at line 133 of file qdeclarativedom.cpp.

134 {
135  return d->imports;
136 }
QSharedDataPointer< QDeclarativeDomDocumentPrivate > d
QList< QDeclarativeDomImport > imports

◆ load()

bool QDeclarativeDomDocument::load ( QDeclarativeEngine engine,
const QByteArray data,
const QUrl url = QUrl() 
)

Loads a QDeclarativeDomDocument from data.

data should be valid QML data. On success, true is returned. If the data is malformed, false is returned and QDeclarativeDomDocument::errors() contains an error description.

See also
QDeclarativeDomDocument::loadError()

Definition at line 145 of file qdeclarativedom.cpp.

146 {
147  d->errors.clear();
148  d->imports.clear();
149 
152 
153  if(td->isError()) {
154  d->errors = td->errors();
155  td->release();
156  return false;
157  } else if(!td->isCompleteOrError()) {
159  error.setDescription(QLatin1String("QDeclarativeDomDocument supports local types only"));
160  d->errors << error;
161  td->release();
162  return false;
163  }
164 
165  for (int i = 0; i < td->parser().imports().size(); ++i) {
166  QDeclarativeScriptParser::Import parserImport = td->parser().imports().at(i);
167  QDeclarativeDomImport domImport;
168  domImport.d->type = static_cast<QDeclarativeDomImportPrivate::Type>(parserImport.type);
169  domImport.d->uri = parserImport.uri;
170  domImport.d->qualifier = parserImport.qualifier;
171  domImport.d->version = parserImport.version;
172  d->imports += domImport;
173  }
174 
175  if (td->parser().tree()) {
176  d->root = td->parser().tree();
177  d->root->addref();
178  }
179 
180  td->release();
181  return true;
182 }
bool isError() const
Returns true if the status is Error.
void setDescription(const QString &)
Sets the error description.
The QDeclarativeDomImport class represents an import statement.
QDeclarativeParser::Object * root
QSharedDataPointer< QDeclarativeDomImportPrivate > d
#define error(msg)
bool isCompleteOrError() const
Returns true if the status is Complete or Error.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QDeclarativeTypeLoader typeLoader
QList< QDeclarativeError > errors
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QSharedDataPointer< QDeclarativeDomDocumentPrivate > d
The QDeclarativeError class encapsulates a QML error.
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QDeclarativeError > errors() const
Return the errors on this blob.
QDeclarativeTypeData * get(const QUrl &url)
Returns a QDeclarativeTypeData for the specified url.
const QDeclarativeScriptParser & parser() const
QDeclarativeParser::Object * tree() const
QList< QDeclarativeDomImport > imports

◆ operator=()

QDeclarativeDomDocument & QDeclarativeDomDocument::operator= ( const QDeclarativeDomDocument other)

Assign other to this QDeclarativeDomDocument.

Definition at line 124 of file qdeclarativedom.cpp.

125 {
126  d = other.d;
127  return *this;
128 }
QSharedDataPointer< QDeclarativeDomDocumentPrivate > d

◆ rootObject()

QDeclarativeDomObject QDeclarativeDomDocument::rootObject ( ) const

Returns the document's root object, or an invalid QDeclarativeDomObject if the document has no root.

In the sample QML below, the root object will be the QDeclarativeItem type.

Text {
text: "Hello World"
}
}

Definition at line 208 of file qdeclarativedom.cpp.

209 {
211  rv.d->object = d->root;
212  if (rv.d->object) rv.d->object->addref();
213  return rv;
214 }
QDeclarativeParser::Object * root
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d
QSharedDataPointer< QDeclarativeDomDocumentPrivate > d
The QDeclarativeDomObject class represents an object instantiation.

Properties

◆ d

QSharedDataPointer<QDeclarativeDomDocumentPrivate> QDeclarativeDomDocument::d
private

Definition at line 97 of file qdeclarativedom_p.h.

Referenced by errors(), imports(), load(), operator=(), and rootObject().


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