[Interest] Double destruction of Qt objects in Qt example code?

Sean Harmer sh at theharmers.co.uk
Sat Aug 18 19:08:26 CEST 2012

Hi K Frank,

On Saturday 18 August 2012 12:38:43 K. Frank wrote:
> Hello List!
> I see the following code snippet in some Qt documentation:
>    QGraphicsScene scene;
>    scene.addText("Hello, world!");
>    QGraphicsView view(&scene);
>    view.show();
> (From http://doc.qt.nokia.com/4.7-snapshot/qgraphicsview.html)
> Both scene and view are automatic variables.  If this example were
> taken literally, would it lead to a double-destruction bug?

Nope. QObject is smart enough that when a child QObject is destroyed it 
informs its parent of this and the parent removes it from the list of child 
objects it is responsible for. This way, double deletion is avoided.



This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

More information about the Interest mailing list