The question is the following: I initialized QGraphicsEllipseItem * ellipse and marked it on QGraphicsScene, how would it be correct to remove this ellipse from the scene?

    1 answer 1

    If you delete it completely, then you can just delete 'om (Qt takes care of all descendants and notifies the scene), and if only from the scene (and then use it for some other reason), then QGraphicsScene::removeItem() .

    • The point is that I tried to use delete, I get the error << malloc: *** error for object 0x7ffeec820450: I’m not working with objects like QGraphicsItem, but not QGraphicsEllipseItem (Line, Rect) and so on ; ( - Marshal
    • @Marshal, Disagree, QGraphicsItem is an ancestor for QGraphicsEllipseItem, so removeItem is suitable for all descendants. - gil9red
    • Well, I can understand something, but nevertheless, the compiler either complains about the type, or << call to a non-static member function without an object argument >> - Marshal
    • @Marshal, something is wrong, add code to the question (create, delete and, if there is, some unusual intermediate actions) ... the minimum reproducible example is Fat-Zer
    • @ Fat-Zer Well, in general, I initialize the scene itself scene = new QGraphicsScene (this) The next moment - I have a point class, which, in addition to the coordinates, stores QGraphicsEllipseItem * ellipse and the draw function in the public, where the ellipse itself will draw. In the same class, I wanted to make an ellipse removal function, void Point :: remove () {QGraphicsScene :: removeItem (this-> ellipse); delete this-> ellipse; } - Marshal