O'Reilly logo

Qt 5 Projects by Marco Piccolino

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

QML engines and contexts

Any QML component requires an environment where it should be instantiated. Such an environment is the sum of a QQmlContext (http://doc.qt.io/qt-5.9/qqmlcontext.html), which is responsible for exposing data to the QML component, and a QQmlEngine (http://doc.qt.io/qt-5.9/qqmlengine.html), which is responsible for instantiating the component and managing a hierarchy of QQmlContexts. The QQmlContext manages property bindings and contextual properties like the C++ object instances we want to expose to the QML UI.

Looking at GUI's main.cpp, you'll see that Qt Creator's application template created these two lines of code for us:

QQmlApplicationEngine engine;engine.load(QUrl(QLatin1String("qrc:/main.qml")));

In the first ...

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