[PyQt] Adding methods to C++-created objects

Phil Thompson phil at riverbankcomputing.co.uk
Wed Oct 17 18:18:27 BST 2007


On Wednesday 17 October 2007, Giovanni Bajo wrote:
> Hello,
>
> I get random crashes from code like this one:
>
> class MyDelegate(QItemDelegate):
>      def createEditor(self, *args):
>          ed = QItemDelegate.createEditor(self, *args)
>          ed.foo = bar  # adding stuff to python instance
>          ed.foo2 = lambda: bar
>          return ed
>
>      def setModelData(self, editor, model, index):
>          print editor.foo   # accessing python stuff added before
>
>
> I think it's either a PyQt bug or simply this usage pattern is not fully
> supported. If this is something that should work, I'll work on a repro
> recipe.

It should work (assuming the parent argument to createEditor() is not 
None/NULL).

The qitemdelegate.sip file looks like it might be missing some annotations. 
The following may help...

  virtual QWidget *createEditor(QWidget *parent /TransferThis/,
      ...) const /Factory/;

...but there may still be issues. A test case would be very helpful.

Phil


More information about the PyQt mailing list