Results 1 to 6 of 6

Thread: Proper QList usage

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Proper QList usage

    Are you sure the code you posted is correct? It shouldn't compile... QList<DElement> and QList<DElement*> types are not compatible and you are treating them as such, so there is obviously some typo here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Dec 2009
    Posts
    33
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Proper QList usage

    Ah, sorry, they should all be QList<DElement *> *.

    Will there be a memory leak if I remove "delete prev;"? The Stack destructor deletes the list contents, so I guess not. Removing the line didn't make it work. Seems the pointers are invalid before undo() is called.

    Whew! I figured it out. The operators were deleting the objects. Sorry, there was no way you could have known that. I'm developing an arbitrary-precision RPN calculator program. Do you think I should start a sourceforge project? It's still in the very early stages obviously...
    Last edited by space_otter; 18th June 2010 at 19:27.

  3. #3
    Join Date
    Dec 2009
    Posts
    33
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Proper QList usage

    Does QList support abstract classes though?

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 94 Times in 86 Posts

    Default Re: Proper QList usage

    Quote Originally Posted by space_otter View Post
    Does QList support abstract classes though?
    What do you mean? You can store anything you like in a QList, but if you're trying to store classes derived from some abstract base class, you'll have to store pointers to the base class, not the derived classes themselves. That's how C++ handles such things.

    QList itself, however, doesn't care what you store in it, as long as all the elements match the template type.

Similar Threads

  1. Copying an QList into a new, sorted QList.
    By Thomas Wrobel in forum Newbie
    Replies: 3
    Last Post: 11th January 2010, 18:27
  2. Replies: 1
    Last Post: 13th November 2009, 01:45
  3. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 08:42
  4. QList usage in place QPtrList
    By darpan in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 15:41
  5. Proper way to #include Qt?
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 02:15

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.