Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Destructor overriding

Destructor overriding

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daylight
    wrote on last edited by
    #1

    I examined the [url='http://qt-project.org/doc/qt-4.8/graphicsview-diagramscene.html']Diagram Scene Example[/url] and faced this code:

    [code]void DiagramItem::removeArrows()
    {
    foreach (Arrow *arrow, arrows) {
    arrow->startItem()->removeArrow(arrow);
    arrow->endItem()->removeArrow(arrow);
    scene()->removeItem(arrow);
    delete arrow;
    }
    }[/code]

    Where Arrow is:
    [CODE]
    class Arrow : public QGraphicsLineItem
    [/CODE]

    My question is, whether it is adequate to implement DiagramItem::removeArrows() method that way instead of overriding the Arrow's destructor:

    [CODE]
    Arrow::~Arrow()
    {
    startItem()->removeArrow(this);
    endItem()->removeArrow(this);
    }
    [/CODE]

    Then DiagramItem::removeArrows() would look like:
    [CODE]void DiagramItem::removeArrows()
    {
    foreach (Arrow *arrow, arrows) {
    scene()->removeItem(arrow);
    delete arrow;
    }
    }[/CODE]

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      well the only thing that wouldn't work in that case (just by taking a glimpse at the code you wrote not the example) would be the scene()->removeItem(arrow) which should be in the removeArrows function

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Daylight
        wrote on last edited by
        #3

        Oh, yes, this is a mistake. "scene()->removeItem(aarow)" is not needed in destructor, fixed that. But elsewise?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved