Does QGraphicsView get ownership of the associated graphic scene?

I was wondering ... if I highlighted the graphic scene

QGraphicsScene* scene = new QGraphicsScene(); 

and match it with a graphical representation

 this->ui->graphicsView->setScene(scene); 

Does the graphic view take on the role of the scene? In other words, does the graphical view remove the scene in its destructor, or should I delete the scene myself?

+4
source share
1 answer

The answer is no .
This is because Qt allows you to display one model ( QGraphicsScene in this case) in many views, which is a standard function of each model / view structure.

The QGrahpicsView::setScene() documentation does not contain information about what happens with the ownership of the scene, but the situation is the same as in other views; e.g. from the documentation void QWebView::setPage ( QWebPage * page )

The parent QObject of the provided page remains the owner of the object. If the current document is a child of the web view, it will be deleted.

+3
source

Source: https://habr.com/ru/post/1339163/


All Articles