Qt Containers and Custom Superclass and Subclasses



  • Greetings.

    Given a superclass 'BaseT' and its subclass 'ChildT', suppose you have a QList< ChildT* > and you want to convert it to a QList< Base* >.

    Although I raised my question in a general way, my concern about this matter arises from a particular problem: I have a function that receives as parameter one QList< BaseT* > and I need to use this function with one QList< ChildT1* >, QList< ChildT2* > and QList< ChildT3* >... being ChildT1, ChildT2 ChildT3 three different BaseT subclasses.

    What are my options to achieve this?

    Thanks in advance for your help and/or suggestions.


  • Lifetime Qt Champion

    Hi,

    @
    QList<ChildT1 *> childT1List;
    QList<BaseT *> basetTlist = *reinterpret_cast< QList<BaseT *> *>(&childT1List);
    @

    Inspired from "here":http://comments.gmane.org/gmane.comp.lib.qt.general/38943


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.