[PyQt] Help tracking down intermittent segfault using QGraphicsItem

Andreas Pakulat apaku at gmx.de
Sat Jan 5 21:58:28 GMT 2013


Hi,

Am Samstag, 5. Januar 2013 schrieb :

> On 05.01.2013, 16:50:29 Andreas Pakulat wrote:
> [...]
> > Often a segfault is caused by using a pointer (in C++) which points to
> > a memory location thats not valid anymore, for example because the
> > object has been deleted already. In the context of PyQt this can
> > happen when you stop keeping references to objects that or instances
> > of C++-provided classes in python. In such a case the C++ parts of the
> > object will be deleted and thus any other C++ code that has a
> > reference to the object will crash when it tries to access the object.
> > I think thats the most common problem one encounters with PyQt4.
>
> While this is certainly true in general, I'd say that sip goes to
> great length in order to avoid that kind of crash by carefully
> observing who owns what. It is aware of the parent-child memory
> management of Qt. A python program should never be able to cause a
> crash. Is there any place in PyQt where the Python code has to keep
> references to keep the program going?


Thats not always possible, it only works for objects which tell sip when
they are deleted, for example QObject instances. Other Qt types do not
support object life tracking like QObject, so sip has no way to know that
it should not delete the object when the python reference is garbage
collected.

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130105/c5113888/attachment.html>


More information about the PyQt mailing list