Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Containers and Custom Superclass and Subclasses
Forum Updated to NodeBB v4.3 + New Features

Qt Containers and Custom Superclass and Subclasses

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 650 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    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.

    Isaac Pérez
    Programming is understanding.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved