[PyKDE] Python functions as slots

Konrad Hinsen hinsen at cnrs-orleans.fr
Mon Sep 30 20:52:00 BST 2002


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()                                            

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.




More information about the PyQt mailing list