Entity collections

To implement entity collections, we need to leverage some more advanced C++ techniques, and we will take a brief break from our conventions so far, implementing multiple classes in a single header file.

Create entity-collection.h in cm-lib/source/data, and in it, add our namespaces as normal and forward declare Entity:

#ifndef ENTITYCOLLECTION_H
#define ENTITYCOLLECTION_Hnamespace cm {
namespace data {
    class Entity;}}#endif

Next, we’ll walk through the necessary classes in turn, each of which must be added in order inside the namespaces.

We first define the root class, which does nothing more than inheriting from QObject and giving us access to all the goodness that it brings, such as object ownership and signals. This ...

Get End to End GUI Development with Qt5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.