Re: Containers with derived classes? (QMap or QList)
if you store a list of fruits, then you should only need to treat them as fruits, otherwise your design is wrong (liskov substitution principle, I think).
You should only need to use virtual methods on Fruit to get specialised behaviour, and should not need to recover the exact type.
Tell me, how are the available properties of Apple different to that of Banana?
This is basic C++ and nothing to do with Qt.
If you make a QList<Fruit>, then you have only Fruit objects. If you make a QList<Fruit*>, then you may have Fruit, Apple and Banana...
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
Bookmarks