PDA

View Full Version : Q3Ptrlist v/s QList



joseph
25th September 2007, 08:10
Hi,

Can anybody tell me , what all are the "benefits and isues" while moving from Q3PtrList to QList.

Will i get good perfomance while using QList instead of Q3PtrList.

i am planing to use the QList like to this ( almost everywhere in my project )


QList< MyWidget* > _list;



Old code in my project


Q3PtrList<MyWidget> _list;


Please explain the things/places where i have to give extra care while using this QList , as it is dealing with <MyWidget *> .

thank you

wysota
25th September 2007, 10:40
No extra care (maybe one - look out not to compare pointers instead of objects when you use sorting or equality), no cons. Just move to QList. You'll get an improved speed and less dependencies (Q3PtrList is part of Q3Support).

joseph
25th September 2007, 11:20
Thanks wysota



look out not to compare pointers instead of objects when you use sorting or equality


can you please explain this cenario...??

wysota
25th September 2007, 11:27
QList contains objects and QPtrList contains pointers. Thus the equality or lessThan operators for QList operate on objects and not pointers. Because QPtrList is aware of the fact that it holds pointers, it knows what to do to compare actual objects. This is not the case with QList (it doesn't know that you passed a pointer to it), so when you ask it to do a comparison it will compare pointers directly without dereferencing them.

I don't know if that's clear, so you can make a simple test - use qSort() to sort a QList of pointers and Q3PtrList of pointers - you'll see that results will differ.