PDA

View Full Version : How to do a 1:N relationship between classes in Qt?



viktoria.nemkin
28th June 2016, 10:07
Hello!

I have two classes that have a 1:N relationship with each other, e.g. and Item class that is connected to an ItemType class. I want to be able to decide with a given Item object and ItemType object if the Item is of that type.

My idea was to use unique ids for both classes and have a member in Item that stores its ItemType's id. I see Qt has a class named QUuid, but it has no copy constructor. I know I can still hack it, e.g. convert the QUuid to a string, and store that in the Item class, but this idea seems to be going agains the intentions of QUuid.

What is the correct way to do this in Qt?

Thank you,
Viki

anda_skoa
28th June 2016, 13:39
Why do you think that QUuid doesn't have a copy constructor?

Cheers,
_

viktoria.nemkin
28th June 2016, 13:58
Oops, it has one, sorry.

I looked at the documentation and it was not listed there: http://doc.qt.io/qt-5/quuid-members.html
Since QObject does not have one, I assumed it was the case here too, without trying it out.

anda_skoa
28th June 2016, 16:39
it doesn't have an overloaded one.

The rule for C++ is, that a class has a copy constructor and assignment operator created by default and a developer can replace them if they choose to.

Cheers,
_