Parsing JSON in QML

Let's rewrite the weather demo in QML. You will find out how easy and elegant it is to write such an application in QML. Since the XML part is already covered in the previous chapter, we'll focus on parsing JSON this time.

First, create a new Qt Quick application project named Weather_QML. Keep the other settings as default, which means we use Qt Quick Controls. Remember to tick the checkbox of the Android kit.

Create a new QML file named Weather.qml to mimic the Weather class in the previous C++ code. This file is pasted here:

import QtQuick 2.3 import QtQuick.Controls 1.2 Rectangle { Column { anchors.fill: parent spacing: 6 Label { id: location width: parent.width fontSizeMode: Text.Fit minimumPointSize: 9 font.pointSize: 12 ...

Get Qt 5 Blueprints now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.