[Qt-interest] QList<T> conversion

Gustavo de Sá Carvalho Honorato gustavohonorato at gmail.com
Tue Feb 1 14:31:02 CET 2011


On Fri, Jan 28, 2011 at 8:56 PM, Thiago Macieira <thiago at kde.org> wrote:
>
> On Friday, 28 de January de 2011 19:58:12 Gustavo de Sį Carvalho Honorato
> wrote:
> > Hi,
> >
> > is it possible to convert QList<A*> to QList<QObject*>, where A inherits
> > from QObject? I would like to do this without create a new QList<QObject*>
> > container and typecasting each element before add into this new one. Is
> > there any better solution than that?
>
> Disclaimer: if you tell anyone I told you this, I'll deny any knowledge of the
> fact.

I've read about reinterpred_cast and I think the reason of your
disclaimer is because the use of reinterpret_cast could be dangerous.
What it's not clear to me is how and which cases reinterpret_cast
could be dangerous. I suppose that in this case it's safe to use
right?

>
>    QList<A *> list;
>    QList<QObject *> objectList  *reinterpret_cast<QList<QObject *>*>(&list);
>
> The data structures in QList<T*> are isomorphic for all T.

What you mean with isomorphic? I understand that this concept is
related to types with same structure or size but different ancestry.
So, I deduced that casting two types with different size is the
problem of using reinterpret_cast. Is it right?

>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>  Senior Product Manager - Nokia, Qt Development Frameworks
>      PGP/GPG: 0x6EF45358; fingerprint:
>      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>
> Content-
> ype: application/pgp-signature; name"signature.asc"
> Content-Description: This is a digitally signed message part.
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
>
> iD4DBQBNQ0m3M/XwBW70U1gRAgyGAJ9xU10Cw/Prh1iDyUlrZwAnqshczQCY/FgD
> qqbdi8nIloZPC3NVmMZ1Fg=
> cZEd
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list