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

Exposing the groceryItems list to QML

We have already exposed the GroceryItems entity from C++ to QML via the groceryItems context property. However, if we want to get access from QML to the GroceryItem list and take advantage of the power of property bindings, so that the UI updates automatically whenever the list changes, we need to expose the list as a property of GroceryItems. For this to happen, we get back to grocery_items.h and add the property, as follows:

...class GroceryItems : public QObject{    Q_OBJECT    Q_PROPERTY(QVariantList list READ list NOTIFY listChanged)

With this macro, we are creating a property called list of type  QVariantList. This property makes use of the following methods and signals when we read the property; we are ...

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