[Interest] QGaphicsItem deletion
Igor Mironchik
igor.mironchik at gmail.com
Wed Jun 15 18:00:34 CEST 2016
Hello.
On 15.06.2016 16:59, Konstantin Shegunov wrote:
> Hello,
>
>
> On Wed, Jun 15, 2016 at 4:15 PM, Igor Mironchik
> <igor.mironchik at gmail.com <mailto:igor.mironchik at gmail.com>> wrote:
>
> Parent of the handles is the same as Line's. But Line own objects
> of handles with QScopedPointer.
>
>
> This doesn't sound right. If the handles are not children to the line,
> then the line doesn't own them. Leaving semantics aside, it sounds
> you're trying to "hijack" the ownership from the parent by using these
> scoped pointers.
Exactly. I need to Line be as parent of handles but they should be
parented to the scene (read form in my app) because I need
boundingRect() to return exactly bounding rectangle of the line without
handles. An I need handles to be removed with the Line if Line deleted.
I know that I can implement my own method in Line like
boundingRectOfLine() and make handles children of Line. May be it would
be a better solution, but at this time I have such code and it work...
> So my question is it possible that handle will be deleted before
> Line, so QScopedPointer will try to free already deleted pointer?
>
>
> From your description I'd guess this is exactly what's happening.
Here you aren't right. In d_tor() of QGraphicsScene I see:
while (!d->topLevelItems.isEmpty())
delete d->topLevelItems.first();
where topLevelItems are in creating order...
and in QGraphicsItem d_tor()
while (!d_ptr->children.isEmpty())
delete d_ptr->children.first();
So when Line deleted it places before handles in children list, and
before Line deleted handles already deleted and removed from children list.
>
> Kind regards.
>
>
> On Wed, Jun 15, 2016 at 4:15 PM, Igor Mironchik
> <igor.mironchik at gmail.com <mailto:igor.mironchik at gmail.com>> wrote:
>
> Hi folks,
>
> Let's say I have QGraphicsItem, let it be Line. This Line has move
> handles - another QGraphicsItems, rectangles. Parent of the
> handles is the same as Line's. But Line own objects of handles
> with QScopedPointer.
>
> When Line creates in c_tor() it creates handles, so handles adds
> to the scene after Line. When I delete Line from the scene by hand
> everything is fine: Line deletes and QScopedPointers free handles.
>
> But if I close application and scene destroys with d_tor() in
> which it deletes all child items. So my question is it possible
> that handle will be deleted before Line, so QScopedPointer will
> try to free already deleted pointer?
>
> Thank you.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org <mailto:Interest at qt-project.org>
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160615/c4860632/attachment.html>
More information about the Interest
mailing list