[Qt-interest] QList<T> conversion
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Tue Feb 1 15:47:16 CET 2011
On 2011-02-01 Gustavo Gustavo de Sá Carvalho Honorato wrote:
> On Tue, Feb 1, 2011 at 11:42 AM, <Oliver.Knoll at comit.ch> wrote:
>> On 2011-02-01 Gustavo Gustavo de Sá Carvalho Honorato wrote:
>>
>>>> ...
>>>> 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?
>>
>> Isomorphism is a very basic property of any OO-related language. ...
> Oliver, what you described seems like polymorphism to me. Are you saying that
> isomorphism and polymorphism are the same concept?
Ups, sorry, two mistakes done by me: first off, my brain transmogrified "isomorphic" to "polymorphic", and I was describing the later.
To be honest I only know the term "isomorphic" in the context of algebra, not sure what it denotes in the context of OO languages. Since we are talking about some kind of "sets" (aka "lists") the term "isomorphic" here probably really means that they are "structurally equal" and... uh well.... ;) As an exercise for the reader refer to https://secure.wikimedia.org/wikipedia/en/wiki/Isomorphism ;)
Second, I only now realize that you actually asked to "downcast" (from A to its base class QObject) every item in the list, probably because you need to match the signature of some method, as in
// A inherits from QObject
QList<A *> items;
QList<QObject *> objects = reinterpret_cast<QList<QObject *> >(items);
doFoo(objects);
with
void doFoo(QList<QObject *> objects) {...}
I guess that is your use case, right?
I don't see why "downcasting" should be dangerous, even though it generally hints at some "design issues".
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list