[Interest] Representing to-many relationships in property system?

Nikos Chantziaras realnc at gmail.com
Thu Oct 11 13:25:07 CEST 2012


On 11/10/12 01:07, Chris Meyer wrote:
> The Qt property system easily represents properties (scalars) and
> to-one relationships (objects) using the Q_PROPERTY macro.

No, not really.  This isn't SQL.  It's C++.  You cannot just declare 
relationships.  You will need to implement them on your own.


> However, what is the best way to represent to-many relationships?
>
> For instance, I can represent have an Employee and define a property
> for the employee's name (scalar string) and his company (object). But
> if I define a Company, how to I provide access to the company's
> employees (list of objects)?

There are multiple ways to implement this.  The most straightforward is 
to have the employee's constructor add the object to a list maintained 
by Company, and remove itself from that list in the destructor.

But this sounds fishy.  If you need to maintain data on employees and 
companies, you either store that as data on disk using your own format, 
or use a database.  You do *not* design a C++ class hierarchy around it.




More information about the Interest mailing list