[Kde-games-devel] Review Request: Porting KBounce to QGraphics

Ian Wadham ianw2 at optusnet.com.au
Sun May 20 03:12:40 UTC 2012



> On May 19, 2012, 7:23 a.m., Ian Wadham wrote:
> > /trunk/KDE/kdegames/kbounce/board.h, lines 46-47
> > <http://svn.reviewboard.kde.org/r/6950/diff/2/?file=48003#file48003line46>
> >
> >     I am in some confusion here as to who is the (Qt) parent or owner of the KBounceBoard in the new code.  Also I think you will find that QGraphicsItem and QGraphicsItemGroup are already descended from QObject, so no need to inherit QObject.
> 
> Roney Gomes wrote:
>     KBounceBoard has no parent. It happens because it is a top level item and top level items doesn't need a parent, they are just elements of the scene.
>     
>     It may occur, however, that in some situations the scene is treated as the parent of top level items. It is better explained in the following excerpt I took from [1]:
>     
>     "At item's position is the coordinate of the item's center point in its parent's coordinate system; sometimes referred to as parent coordinates. The scene is in this sense regarded as all parent-less items' "parent". Top level items' position are in scene coordinates."
>     
>     In this case KBounceGameWidget has a pointer to a KBounceBoard object which is created and added to the scene when KBounceGameWidget's constructor is called.
>     
>     Regarding your second point, you can see here [2] that QGraphicsItem is not a descendant of any other class.
>     
>     [1] http://qt-project.org/doc/qt-4.8/graphicsview.html
>     [2] http://qt-project.org/doc/qt-4.8/qgraphicsitem.html

Yes, you are right about the second point.  It is QGraphicsScene that is descended from QObject.  And you *are* doing an addItem() for KBounceBoard.

I was concerned about memory management and possible leaks.  Parenting of QObject's descendants has an effect on that.  The destructor of QGraphicsScene is documented as deleting all QGraphicsItem's in the scene.  But what deletes your QGraphicsScene?

As far as I can see, it *will* happen, although your scene has no parent, because KBounceGameWidget::m_scene will get deleted when the widget is deleted, and the widget gets deleted because its parent is the main window.  I think it is more usual to create the scene using "new" and maybe declare its parent to be some object that will get deleted or maybe delete it explicitly somewhere.

Anyway, please close this issue now.


- Ian


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://svn.reviewboard.kde.org/r/6950/#review10799
-----------------------------------------------------------


On May 19, 2012, 12:20 p.m., Roney Gomes wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://svn.reviewboard.kde.org/r/6950/
> -----------------------------------------------------------
> 
> (Updated May 19, 2012, 12:20 p.m.)
> 
> 
> Review request for KDE Games.
> 
> 
> Description
> -------
> 
> Following the timeline defined in my proposal, here is the port of the first game.
> 
> 
> Diffs
> -----
> 
>   /trunk/KDE/kdegames/kbounce/ball.h 1295688 
>   /trunk/KDE/kdegames/kbounce/ball.cpp 1295688 
>   /trunk/KDE/kdegames/kbounce/board.h 1295688 
>   /trunk/KDE/kdegames/kbounce/board.cpp 1295688 
>   /trunk/KDE/kdegames/kbounce/gamewidget.h 1295688 
>   /trunk/KDE/kdegames/kbounce/gamewidget.cpp 1295688 
>   /trunk/KDE/kdegames/kbounce/wall.h 1295688 
>   /trunk/KDE/kdegames/kbounce/wall.cpp 1295688 
> 
> Diff: http://svn.reviewboard.kde.org/r/6950/diff/
> 
> 
> Testing
> -------
> 
> I observed the game under the following conditions:
> - Before the first match
> - During a match
> - Closing a match
> 
> 
> Thanks,
> 
> Roney Gomes
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-games-devel/attachments/20120520/e2409d85/attachment-0001.html>


More information about the kde-games-devel mailing list