diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-05-20 04:35:07 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-05-20 04:37:56 (GMT) |
commit | 1057b0a334c9ac7e7e1f3287935fad06de423108 (patch) | |
tree | b5f577dd6176e6c9698fe24aa5df281befc20357 /src/declarative/util/qdeclarativexmllistmodel.cpp | |
parent | e75088323ae15604139ddfd66b85cc3b8d43abeb (diff) | |
download | Qt-1057b0a334c9ac7e7e1f3287935fad06de423108.zip Qt-1057b0a334c9ac7e7e1f3287935fad06de423108.tar.gz Qt-1057b0a334c9ac7e7e1f3287935fad06de423108.tar.bz2 |
Add XmlListModel::errorString()
Diffstat (limited to 'src/declarative/util/qdeclarativexmllistmodel.cpp')
-rw-r--r-- | src/declarative/util/qdeclarativexmllistmodel.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 4a374a5..cae1d3a 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -423,6 +423,7 @@ public: int highestRole; QNetworkReply *reply; QDeclarativeXmlListModel::Status status; + QString errorString; qreal progress; int queryId; QStringList keyRoleResultsCache; @@ -495,10 +496,11 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla </rss> \endcode - Then it could be used to create the following model: + A XmlListModel could create a model from this data, like this: \qml XmlListModel { + id: xmlModel source: "http://www.mysite.com/feed.xml" query: "/rss/channel/item" XmlRole { name: "title"; query: "title/string()" } @@ -511,6 +513,16 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla model item attributes; here, each model item will have \c title and \c pubDate attributes that match the \c title and \c pubDate values of its corresponding \c <item>. + The model could be used in a ListView, like this: + + \qml + ListView { + width: 180; height: 300 + model: xmlModel + delegate: Text { title + " (" + pubDate + ")" } + } + \endqml + \section2 Using key XML roles @@ -722,7 +734,8 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati \o XmlListModel.Null - No XML data has been set for this model. \o XmlListModel.Ready - The XML data has been loaded into the model. \o XmlListModel.Loading - The model is in the process of reading and loading XML data. - \o XmlListModel.Error - An error occurred while the model was loading. + \o XmlListModel.Error - An error occurred while the model was loading. See errorString() for details + about the error. \endlist \sa progress @@ -755,6 +768,12 @@ qreal QDeclarativeXmlListModel::progress() const return d->progress; } +QString QDeclarativeXmlListModel::errorString() const +{ + Q_D(const QDeclarativeXmlListModel); + return d->errorString; +} + void QDeclarativeXmlListModel::classBegin() { Q_D(QDeclarativeXmlListModel); @@ -807,6 +826,7 @@ void QDeclarativeXmlListModel::reload() d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects, d->keyRoleResultsCache); d->progress = 1.0; d->status = Loading; + d->errorString.clear(); emit progressChanged(d->progress); emit statusChanged(d->status); return; @@ -816,6 +836,7 @@ void QDeclarativeXmlListModel::reload() d->queryId = XMLLISTMODEL_CLEAR_ID; d->progress = 1.0; d->status = Loading; + d->errorString.clear(); emit progressChanged(d->progress); emit statusChanged(d->status); QTimer::singleShot(0, this, SLOT(dataCleared())); @@ -824,6 +845,7 @@ void QDeclarativeXmlListModel::reload() d->progress = 0.0; d->status = Loading; + d->errorString.clear(); emit progressChanged(d->progress); emit statusChanged(d->status); @@ -854,6 +876,7 @@ void QDeclarativeXmlListModel::requestFinished() d->redirectCount = 0; if (d->reply->error() != QNetworkReply::NoError) { + d->errorString = d->reply->errorString(); disconnect(d->reply, 0, this, 0); d->reply->deleteLater(); d->reply = 0; @@ -919,6 +942,7 @@ void QDeclarativeXmlListModel::queryCompleted(const QDeclarativeXmlQueryResult & d->data = result.data; d->keyRoleResultsCache = result.keyRoleResultsCache; d->status = Ready; + d->errorString.clear(); d->queryId = -1; bool hasKeys = false; |