[Qt-interest] Application crashing after deleting
Arnold Krille
arnold at arnoldarts.de
Sat Sep 26 22:38:15 CEST 2009
On Saturday 26 September 2009 22:10:07 Martin Hofius wrote:
> Am Samstag, 26. September 2009 schrieb Andreas Unger:
> > Hi all,
> >
> > I have a bunch of items on a QGraphicsView. Most of these items have
> > buttons on them. In the slots corresponding to the various buttons, I
> > call a method in a separate manager class which deletes some of the
> > widgets on the main window. However, for some reason, I cannot delete the
> > widget containing the button that was last clicked. Why is this case? How
> > can I make sure that this widget is deleted as well?
> hmm, you want to delete a widget that called the current slot? As far as I
> know slots are used as direct function calls - so I can't imagine that
> deleting this widget in the slot can be safe...
Not necessarily, when crossing thread-boundaries, signals become events.
But a bigger problem is hidden: There might be other events in the loop for
the object you want to delete.
Thats why QObject has the deleteLater() slot which schedules the object for
deletion in the event-loop. Use that for deleting objects and you are safe.
Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090926/ce152251/attachment.bin
More information about the Qt-interest-old
mailing list