[PySide] PySide Pitfalls

Joel B. Mohler jmohler at gamry.com
Tue Sep 16 13:31:28 CEST 2014


On 9/15/2014 10:12 AM, Stephan Deibel wrote:
> Nathan Warmerdam wrote:
>> TL;DR - What are some common gotchas that can lead to a crash even in
>> a simple PySide application.
> One is trying to keep a reference to any wrapped object that is not a
> descendent of QObject.  There is no life cycle management so the
> underlying C++ object can be freed and the Python reference can even be
> replaced with another C++ object.  I've seen this with QEvents in the
> context of event filters and it also applies to QIcon, QStandardItem,
> and QListWidgetItem, which maybe is a clue to why it crashed in your case.

In similar spirit (although these are QObject derived), I have had 
troubles with QMenu usages causing trouble if I don't hold a python 
reference to the QMenu.   I have also have crashes when I don't hold a 
reference to the QItemSelectionModel returned from 
QAbstractItemView::selectionModel().

QItemSelectionModel issues: 
https://gist.github.com/jbmohler/861eb9e16b209cb938ff (no crashes as 
posted, but see OPTION comments);  I think this is simply a ridiculous 
bug and I can't really fathom it.

I have no luck reproducing the QMenu issue right now in a snippet so 
that's no help to you -- and it may be a figment of my imagination.

Joel





More information about the PySide mailing list