Qml Weather
Esta é uma demonstração básica que mostra como usar os diferentes tipos de gráficos com o QML.

Por padrão, o aplicativo usa dados de teste estáticos para simular uma previsão do tempo. Você também pode obter um ID de aplicativo em http://www.worldweatheronline.com/ para ter acesso à API meteorológica fornecida pelo World Weather Online. Em seguida, basta passar o ID do seu aplicativo como parâmetro para o executável do Qml Weather para que ele utilize dados em tempo real.
Por exemplo:
bin\qmlweather.exe 1234567890abcdef123456Executando o exemplo
Você pode executar o exemplo a partir de:
- Qt Creator
Abra o modo “ Welcome ” e selecione o exemplo em Examples. Para mais informações, consulte Qt Creator: Tutorial: Compilar e executar.
- Qt Extension for Visual Studio Code
Execute o comando ` Qt: Open Qt examples ` a partir de Command Palette e selecione o exemplo na lista. Para mais informações, consulte Qt Extension for Visual Studio Code: Tutorial: Compilar e executar.
Uso de gráficos em aplicativos do Qt Quick
O aplicativo de exemplo usa um ChartView e algumas séries para visualizar dados meteorológicos:
ChartView {
id: chartView
title: "Weather forecast"
BarCategoryAxis {
id: barCategoriesAxis
titleText: "Date"
}
ValueAxis{
id: valueAxisY2
min: 0
max: 10
titleText: "Rainfall [mm]"
}
ValueAxis {
id: valueAxisX
// Hide the value axis; it is only used to map the line series to bar categories axis
visible: false
min: 0
max: 5
}
ValueAxis{
id: valueAxisY
min: 0
max: 15
titleText: "Temperature [°C]"
}
LineSeries {
id: maxTempSeries
axisX: valueAxisX
axisY: valueAxisY
name: "Max. temperature"
}
LineSeries {
id: minTempSeries
axisX: valueAxisX
axisY: valueAxisY
name: "Min. temperature"
}
BarSeries {
id: myBarSeries
axisX: barCategoriesAxis
axisYRight: valueAxisY2
BarSet {
id: rainfallSet
label: "Rainfall"
}
}Para obter dados de previsão do tempo, fazemos uma solicitação HTTP GET ao World Weather Online. Solicitamos a resposta no formato de dados JSON.
// Make HTTP GET request and parse the result
var xhr = new XMLHttpRequest;
xhr.open("GET",
"http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key="
+ weatherAppKey);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var a = JSON.parse(xhr.responseText);
parseWeatherData(a);
}
}
xhr.send();A resposta JSON contém uma matriz de dados de previsão:
// Loop through the parsed JSON
for (var i in weatherData.data.weather) {
var weatherObj = weatherData.data.weather[i];Esses dados são então utilizados como entrada para nossas séries e para um ListModel, que usamos como contêiner para as URLs dos ícones meteorológicos:
// Store temperature values, rainfall and weather icon.
// The temperature values begin from 0.5 instead of 0.0 to make the start from the
// middle of the rainfall bars. This makes the temperature lines visually better
// synchronized with the rainfall bars.
maxTempSeries.append(Number(i) + 0.5, weatherObj.tempMaxC);
minTempSeries.append(Number(i) + 0.5, weatherObj.tempMinC);
rainfallSet.append(weatherObj.precipMM);
weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.