O'Reilly logo

Qt 5 Blueprints by Symeon Huang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing XML results

Although a lot of APIs provide both XML and JSON results, you may still find that some of them only offer one format. Besides, you might feel that parsing JSON in C++/Qt is not a pleasant process. You may remember how easy it is to parse the XML model in QML/Qt Quick. Well, let's see how to do this in C++/Qt.

To make use of an xml module, we have to add xml to QT in the project file, the same way we did to network. This time, Qt has provided an XML reader class called QXmlStreamReader to help us parse the XML documents. The first thing we need to do is to change the updateData function in the Weather class to let the Yahoo! Weather API return an XML result.

void Weather::updateData(const QString &woeid) { QUrl url("https://query.yahooapis.com/v1/public/yql?q=select ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required