Reputation: 361
Is there a container who can store different types (yes, I really need to work with different kind of types) in Qt? I must create a new class to do this? If so, could you give me a hint to create it?
Upvotes: 0
Views: 198
Reputation: 56479
Most of containers in Qt are template based, then you can use them for different static types.
Another option is to use use QVariant
, for example: QVector<QVariant> vec;
.
A more dynamic solution is to use polymorphism, you can store pointers to a base class and so on.. .
PS: As a general rule, you should avoid this patterns. From Effective C++, by Scott Meyers:
Anytime you find yourself writing code of the form "if the object is of type T1, then do something, but if it's of type T2, then do something else," slap yourself.
Upvotes: 1