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

Andrei Kopats hlamer at tut.by
Sun Aug 24 15:36:16 BST 2014

Hi, David

See my comments below

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.
For me the test also generates RuntimeErrors. But in real big application a
bug sometimes causes exceptions, and sometimes crashes the application. I
don't know why.

> 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.

I expect behavior, described in the QObject:~QObject documentation: "All
signals to and from the object are automatically disconnected"
As you can see in the table, some slots are disconnected, but not all.

Btw, this article was written in January 2014. I used up to date Ubuntu
13.10 for my tests. Pure-C++ case worked fine. But now on PyQt
4.10.3-1ubuntu1 RuntimeError is generated even for clear().

> Regards,
> David
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140824/ebca3d7e/attachment.html>

More information about the PyQt mailing list