Results 1 to 4 of 4

Thread: Q3Ptrlist v/s QList

  1. #1
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Q3Ptrlist v/s QList

    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 )
    Qt Code:
    1. QList< MyWidget* > _list;
    To copy to clipboard, switch view to plain text mode 

    Old code in my project
    Qt Code:
    1. Q3PtrList<MyWidget> _list;
    To copy to clipboard, switch view to plain text mode 

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

    thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Q3Ptrlist v/s QList

    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).

  3. #3
    Join Date
    Feb 2006
    Posts
    157
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: Q3Ptrlist v/s QList

    Thanks wysota

    Quote Originally Posted by wysota View Post
    look out not to compare pointers instead of objects when you use sorting or equality
    can you please explain this cenario...??

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Q3Ptrlist v/s QList

    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.

Similar Threads

  1. Substiture for Q3PtrList in Qt4.2.2
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 11th September 2007, 12:33
  2. QList
    By dragon in forum Qt Programming
    Replies: 11
    Last Post: 9th May 2007, 20:15
  3. using Qlist with a class
    By Havard in forum Qt Programming
    Replies: 10
    Last Post: 24th February 2007, 19:38
  4. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.