[PyKDE] Python functions as slots

2002-09-30 Thread Konrad Hinsen

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.

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde



Re: [PyKDE] Python functions as slots

2002-09-30 Thread Soeren Fietzke

Hi Konrad,

just leave out the receiver object:

app.connect(button, SIGNAL(clicked()), foo)


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

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde



Re: [PyKDE] Python functions as slots

2002-09-30 Thread Hans-Peter Jansen

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?

Hans-Peter

___
PyKDE mailing list[EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde