Results 1 to 14 of 14

Thread: Destructor overriding

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2013
    Posts
    9
    Qt products
    Qt4 Qt5 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Destructor overriding

    I examined the Diagram Scene Example and faced this code:
    Qt Code:
    1. void DiagramItem::removeArrows()
    2. {
    3. foreach (Arrow *arrow, arrows) {
    4. arrow->startItem()->removeArrow(arrow);
    5. arrow->endItem()->removeArrow(arrow);
    6. scene()->removeItem(arrow);
    7. delete arrow;
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    Where Arrow is:
    Qt Code:
    1. class Arrow : public QGraphicsLineItem
    To copy to clipboard, switch view to plain text mode 
    My question is, whether it is better to implement DiagramItem::removeArrows() method that way instead of overriding the Arrow's destructor:
    Qt Code:
    1. Arrow::~Arrow() //Virtual destructor
    2. {
    3. startItem()->removeArrow(this);
    4. endItem()->removeArrow(this);
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    Then DiagramItem::removeArrows() would look like:
    Qt Code:
    1. void DiagramItem::removeArrows()
    2. {
    3. foreach (Arrow *arrow, arrows) {
    4. scene()->removeItem(this);
    5. delete arrow;
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Daylight; 28th February 2013 at 16:09.

Similar Threads

  1. Overriding Proxies
    By jdgrant in forum Qt Programming
    Replies: 0
    Last Post: 25th November 2011, 01:23
  2. Overriding global new
    By branko in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2010, 16:10
  3. overriding QListWidget advice
    By codebehind in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2010, 22:39
  4. Overriding drawRubberBand()
    By andrew.nguyen in forum Qwt
    Replies: 3
    Last Post: 21st April 2010, 06:58
  5. Overriding shortcuts for QGraphicsItems
    By pherthyl in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2008, 22:47

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.