[PyKDE] Python functions as slots

Hans-Peter Jansen hpj at urpla.net
Mon Sep 30 21:54:00 BST 2002

Hi Konrad,

On Monday 30 September 2002 20:50, Konrad Hinsen wrote:
> I have lots of problems using Python functions as slots. As a simple
> illustration, take the following code (an example from Boudewijn Rempt's
> excellent book with an added connect):
>    import sys
>    from qt import *
>    def foo(*args):
>        print args
>    app=QApplication(sys.argv)
>    button=QPushButton("Hello World", None)
>    app.setMainWidget(button)
>    button.show()
>    app.connect(button, SIGNAL("clicked()"), app, foo)
>    app.exec_loop()

This is apparently wrong. Remove app arg from app.connect and 
all goes well. BTW: signal clicked does not take any arguments. 
If you want to pass some custom arguments with signals, roll 
your own (signals).

> When I run this code, I get:
>    Traceback (most recent call last):
>      File "hello1.py", line 14, in ?
>        app.connect(button, SIGNAL("clicked()"), app, foo)
>    TypeError: Argument 4 of QObject.connect() has an invalid type
> This doesn't always happen. For example, I can run the example
> "dial.py" from the same book without problems, although it uses Python
> methods as slots.
> In case it matters, I use PyQt 3.4 and Qt 2.3.1.
> Any idea what is happening here?
> Konrad.

BTW: Are you the Konrad "Signum" Hinsen?


More information about the PyQt mailing list