[Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO
Smith Martin
Martin.Smith at theqtcompany.com
Fri Jul 10 12:32:45 CEST 2015
Maybe it's just me, but I'm still not understanding your explanation, and I don't think you are answering my question:
I have a struct C which is bigger than a pointer. I declare QList<C>. Does your explanation mean that sometimes (most of the time, in fact), the list will become an array of C* instead of an array of C?
martin
________________________________________
From: development-bounces+martin.smith=theqtcompany.com at qt-project.org <development-bounces+martin.smith=theqtcompany.com at qt-project.org> on behalf of Marc Mutz <marc.mutz at kdab.com>
Sent: Friday, July 10, 2015 1:34 PM
To: development at qt-project.org
Subject: Re: [Development] HEADS UP: Don't use QList, use Q_DECLARE_TYPEINFO
On Friday 10 July 2015 13:29:30 Marc Mutz wrote:
> On Friday 10 July 2015 12:18:04 Smith Martin wrote:
> > ...it will create each list entry as a QList<ParsedParameter*> even
> > though I told it not to do that?
>
> Yes. But you told it to do that. You used a _list_.
Ok, I take the bait:
QList is primarily a list, not an array (thus the name). That means that, by
default, references to elements in the list are never invalidated until the
element is removed again. The problem started when someone optimised QList to
contain the elements in an array, but only for *some* types. So, depending on
the type and the QTypeInfo for that flag, QList is either like a std::list or
like a std::vector (QLinkedList / QVector in Qt speak). And it takes great
mental discipline to use it in the proper way, and the resulting code will be
highly fragile and/or extremely inefficient.
Thanks,
Marc
--
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
More information about the Development
mailing list