paazmaya.fi

The Website of Juga Paazmaya | Stories about Web Development, Japanese Martial Arts, Hardware prototyping and travelling

Minimal Qt5 project with QML Engine and resources

This page shows a simple Qt 5 project which uses QQmlEngine, loads Window based QML file from resources and uses a QObject based class for QML/C++ communication.

In case you have not heard about Qt or your knowledge is a bit old, [the Qt White Paper is recommended](https://qt-project.org/wiki/QtWhitepaper This whitepaper describes the Qt C++ framework”) for reading.

In order to have some functionality in the additional “TimeManager” class, it fetches the timezones in a Windows OS. For other OS types, you need to look further. In Qt 5.1 is expected to provide cross platform support for timezones.

Source code for ForExample5.pro now available at GitHub

The main C++ file puts together all the parts needed for an application.

Source code for main.cpp now available at GitHub

The resource system Qt uses a XML file called resources.qrc that lists all the files that are compiled in the resulting binary. In this case there is only the QML file.

Source code for resources.qrc now available at GitHub

The TimeManager class is defined in a header file (.h) and implemented in a C++ file (.cpp).

Source code for timemanager.h now available at GitHub

Please note that due to the Registery dependancy, this implementation only works in Windows.

Source code for timemanager.cpp now available at GitHub

QML file provides the User Interface.

Source code for main.qml now available at GitHub

The whole project is available at the code example repository at GitHub.