开发者

Does a QGraphicsView take ownership over its associated graphics scene?

开发者 https://www.devze.com 2023-02-10 04:35 出处:网络
I was wondering... if I allocate a graphics scene QGraphicsScene* scene = new QGraphicsScene(); and associate it with a graphics view

I was wondering... if I allocate a graphics scene

QGraphicsScene* scene = new QGraphicsScene();

and associate it with a graphics view

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

does the graphics view take ownership of the scene? In开发者_运维技巧 other words, does the graphics view delete the scene in its destructor or should I delete the scene myself?


The answer is no.
That's because Qt makes it possible to display one model (QGraphicsScene in this case) in many views which is a standard feature of every model/view framework.

Documentation of QGrahpicsView::setScene() lacks information about what happens to ownership of a scene but the situation is the same as with others views; for example from documentation of 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号