From 58e154ec33ec1b1aea70fa35a1c5c692fe035df2 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Fri, 21 May 2010 11:12:23 +1000 Subject: Print warnings for xml query syntax errors Task-number: QTBUG-10797 --- src/declarative/util/qdeclarativexmllistmodel.cpp | 17 ++++++++++------- .../tst_qdeclarativexmllistmodel.cpp | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 4d91acc..062e30e 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -128,7 +128,6 @@ struct XmlQueryJob QStringList keyRoleResultsCache; }; - class QDeclarativeXmlQuery : public QThread { Q_OBJECT @@ -355,12 +354,16 @@ void QDeclarativeXmlQuery::doSubQueryJob() QList resultList; if (!queries[i].isEmpty()) { subquery.setQuery(m_prefix + QLatin1String("(let $v := ") + queries[i] + QLatin1String(" return if ($v) then ") + queries[i] + QLatin1String(" else \"\")")); - QXmlResultItems resultItems; - subquery.evaluateTo(&resultItems); - QXmlItem item(resultItems.next()); - while (!item.isNull()) { - resultList << item.toAtomicValue(); //### we used to trim strings - item = resultItems.next(); + if (subquery.isValid()) { + QXmlResultItems resultItems; + subquery.evaluateTo(&resultItems); + QXmlItem item(resultItems.next()); + while (!item.isNull()) { + resultList << item.toAtomicValue(); //### we used to trim strings + item = resultItems.next(); + } + } else { + qWarning().nospace() << "XmlListModel: invalid query: " << queries[i]; } } //### should warn here if things have gone wrong. diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index e1dd6f4..464f9e0 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -224,6 +224,8 @@ void tst_qdeclarativexmllistmodel::roleErrors() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleErrors.qml")); QTest::ignoreMessage(QtWarningMsg, (QUrl::fromLocalFile(SRCDIR "/data/roleErrors.qml").toString() + ":6:5: QML XmlRole: An XmlRole query must not start with '/'").toUtf8().constData()); + QTest::ignoreMessage(QtWarningMsg, "XmlListModel: invalid query: \"age/\""); + //### make sure we receive all expected warning messages. QDeclarativeXmlListModel *model = qobject_cast(component.create()); QVERIFY(model != 0); -- cgit v0.12