[PyQt] PyQt. How to shoot yourself in the foot.

David Boddie david at boddie.org.uk
Sun Aug 24 13:54:03 BST 2014


On Sat, 23 Aug 2014 22:40:51 +0300, Andrei Kopats wrote:

> I just published an article about memory management in PyQt. I think it
> could be interesting for somebody in this list.
> http://enki-editor.org/2014/08/23/Pyqt_mem_mgmt.html
> I'll be thankful for comments and corrections.

With PyQt 4.9.3 I don't get the behaviour you describe for your
5-disconnect.py example. If I uncomment the line

    QTimer.singleShot(1000, lineEdit.purePythonMethod)

then I get this output:

~~~~ C++ lineEdit object destroyed
~~~~ Pure Python method called
Traceback (most recent call last):
  File "5-disconnect.py", line 47, in purePythonMethod
    self.windowTitle()  # generate exception
RuntimeError: wrapped C/C++ object of %S has been deleted
~~~~ Application exited
~~~~ Python lineEdit object destroyed

This isn't a crash as I understand it.

I'm not sure what that example is trying to show. You create a QLineEdit
widget, immediately schedule it for deletion then connect a QTimer signal
to a slot/method.

Did you expect that the connection would fail, or instead that the connection
would be broken when the deleteLater() call takes effect so that the QTimer
signal is not delivered?

It would be helpful if the article said what you thought the expected
behaviour should be.

Regards,

David


More information about the PyQt mailing list