A lightweight Qt/C++ desktop application for retrieving and displaying current weather data from the OpenWeather API.
The app supports search by city name or geographic coordinates, handles asynchronous API requests, parses JSON weather responses, and stores local settings using QSettings in INI format.
The application supports two input modes:
- Search by city name
- Search by geographical coordinates
The input fields are enabled or disabled depending on the selected mode.
Weather data is requested via QNetworkAccessManager and displayed in the GUI.
The application shows:
- temperature
- humidity
- wind speed
- wind direction
- weather description
- city name
- coordinates returned by the API
- weather icon
The application stores local settings using Qt's QSettings with IniFormat.
Stored settings include the OpenWeather API key, the last selected search mode, the last entered city name, and the last used coordinates.
The actual local configuration is described in the Configuration section.
The application handles and displays errors such as:
- missing API key
- invalid API key
- HTTP errors
- network errors
- API-level errors from the OpenWeather response
- Qt 6.x
- C++17 or later
- CMake
- OpenWeather API key
Tested with:
- Qt 6.9.3
- MinGW 64-bit
- Windows 11
The application creates a local config.ini file next to the executable on first launch. The file is ignored by Git and should not be committed.
A config.example.ini file is included to document the expected structure:
[OpenWeather]
apiKey=YOUR_API_KEY_HERE
[Search]
inputMode=cityYou can obtain an API key from:
https://openweathermap.org/api
Weather data:
https://api.openweathermap.org/data/2.5/weather
Weather icons:
https://openweathermap.org/img/wn/<icon>@2x.png
Requests are handled asynchronously using QNetworkAccessManager.
.
├── images/
│ └── app_screenshot.png
├── CMakeLists.txt
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── config.example.ini
├── .gitignore
└── README.md
Important parts of the application:
-
getWeatherByCity()— Builds and sends a weather request using a city name. -
getWeatherByGeoCoords()— Builds and sends a weather request using latitude and longitude. -
processWeatherApiCall()— Parses the JSON weather response and updates the UI. -
processIconApiCall()— Loads and displays the weather icon. -
updateInputFields()— Enables or disables input fields depending on the selected search mode. -
configFilePath()— Defines the path of the localconfig.inifile. -
initializeConfigFile()— Creates a defaultconfig.inifile on first launch. -
loadApiKey()— Reads the OpenWeather API key fromconfig.ini.
Helper functions:
wDirectionToString()— Converts wind degrees to compass directions.wSpeedToBeaufort()— Converts wind speed to the Beaufort scale.
For debugging purposes, the most recent API response is saved to:
Documents/WetterApp_reply.json
This makes it easier to inspect API responses and extend the application.
This is a learning and portfolio project. The focus is on readable Qt/C++ code, basic GUI state handling, asynchronous API access, and safe handling of local API credentials.
