[Solved] PyQt Signals
-
Hi,
When I put this piece of code in my PyQt python script:
@widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function(param))@
It complains this error:
bq. widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function(param))
TypeError: argument 3 of QObject.connect() has an invalid typeIs there any way I can have my function with parameters or is the only way:
@widget.connect(comboBox, QtCore.SIGNAL("activated(QString)"), function)@
Thanks!!
-
Any thoughts? Please & thank you!
-
Thanks for the reply!
I tried this:
@def test(num):
print num
...
comboBox.activated.connect( test(1) )@Got this error:
connect() slot argument should be a callable or a signal, not 'NoneType'
-
Any other ideas?
Thx!!
-
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:
@comboBox.activated.connect(test)@
If you want to pass a parameter to the slot function then you need to use a lambda as follows:
@comboBox.activated.connect(lambda: test(1))@
If you want to pass a variable rather than a static value then:
@
x=10
comboBox.activated.connect(lambda: test(x))
@ -
Thanks so much for the reply/answer :) It works!!!