[PyQt] Bug in sip-4.11.1 and PyQt-4.7.7 ?

Baz Walter bazwal at ftml.net
Tue Sep 28 17:22:50 BST 2010


On 27/09/10 19:45, Gerard Vermeulen wrote:
>   Phil,
>
> when running the following code
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> import PyQt4.Qt as Qt
>
> class MyWidget(Qt.QWidget):
>
>      def __init__(self, parent=None):
>          super(Qt.QWidget, self).__init__(parent)
>
>       # __init__()
>
> # class MyWidget
>
> def bar(widget):
>      pass
>
> # bar()
>
> def foo(widget):
>      print type(widget)
>      # BUG? For me widget is a Python type, but not for widget.connect().
>      widget.connect(widget, Qt.SIGNAL('item_changed(widget)'), bar)

"item_changed" is a new PyQt4 signal defined dynamically. so you need to 
write either:

   widget.connect(widget, Qt.SIGNAL('item_changed'), bar)

or possibly:

   widget.connect(widget, Qt.SIGNAL('item_changed(PyQt_PyObject)'), bar)

you would then emit "item_changed" like this:

   widget.emit(Qt.SIGNAL('item_changed'), widget)

or:

   widget.emit(Qt.SIGNAL('item_changed(PyQt_PyObject)'), widget)

see here for more details:

http://www.riverbankcomputing.com/static/Docs/PyQt4/pyqt4ref.html#pyqt-signals-and-qt-signals

> # foo()
>
> if __name__ == '__main__':
>      application = Qt.QApplication([])
>      widget = MyWidget()
>      foo(widget)
>
> # Local Variables: ***
> # mode: python ***
> # End: ***
>
> I get this traceback:
>
> <class '__main__.MyWidget'>
> Traceback (most recent call last):
>    File "bug.py", line 31, in<module>
>      foo(widget)
>    File "bug.py", line 23, in foo
>      widget.connect(widget, Qt.SIGNAL('item_changed(widget)'), bar)
> TypeError: C++ type 'widget' is not supported as a slot argument type
>
> but isn't widget a Python type? (although derived from a C++ type)

no. widget is an instance of class MyWidget, not a type.


More information about the PyQt mailing list