May 21, 2012

needhelp_gh needhelp_gh
Ant Farmer
54 posts

[Solved] PyQt Signals

 

Hi,

When I put this piece of code in my PyQt python script:

  1. widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function(param))

It complains this error:

widget.connect(comboBox, QtCore.SIGNAL”), function(param))
TypeError: argument 3 of QObject.connect() has an invalid type

Is there any way I can have my function with parameters or is the only way:

  1. widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function)

Thanks!!

 Signature 

————————————————-
http://abstrusegoose.com/432

6 replies

June 4, 2012

needhelp_gh needhelp_gh
Ant Farmer
54 posts

Any thoughts? Please & thank you!

 Signature 

————————————————-
http://abstrusegoose.com/432

June 6, 2012

Erik Janssens Erik Janssens
Lab Rat
11 posts

try :

comboBox.activated.connect( function )

June 6, 2012

needhelp_gh needhelp_gh
Ant Farmer
54 posts

Thanks for the reply!

I tried this:

  1. def test(num):
  2.     print num
  3. ...
  4. comboBox.activated.connect( test(1) )

Got this error:

connect() slot argument should be a callable or a signal, not ‘NoneType’

 Signature 

————————————————-
http://abstrusegoose.com/432

July 6, 2012

needhelp_gh needhelp_gh
Ant Farmer
54 posts

Any other ideas?

Thx!!

 Signature 

————————————————-
http://abstrusegoose.com/432

July 12, 2012

jazzycamel jazzycamel
Ant Farmer
89 posts

The connect function expects a reference to a function, what you are doing is passing it the result of a function. The simple case is:

  1. comboBox.activated.connect(test)

If you want to pass a parameter to the slot function then you need to use a lambda as follows:

  1. comboBox.activated.connect(lambda: test(1))

If you want to pass a variable rather than a static value then:

  1. x=10
  2. comboBox.activated.connect(lambda: test(x))

July 12, 2012

needhelp_gh needhelp_gh
Ant Farmer
54 posts

Thanks so much for the reply/answer :) It works!!!

 Signature 

————————————————-
http://abstrusegoose.com/432

 
  ‹‹ clicked() signal for QListView in Ruby      compiling PythonQt with Qt creator ››

You must log in to post a reply. Not a member yet? Register here!