1

This example works: (Here my function has no input parameters)

    QtCore.QObject.connect(ComboJobType1_1, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(QString)")) ,self.InputChanged())

But, It is necessary for me to send a parameter so I try this: (After updating my function to expect one parameter):

QtCore.QObject.connect(ComboJobType1_1, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(QString)")) ,self.InputChanged("ComboJobType1_1"))

Please note that the first example is working, the only problem (I guess) is sending a parameter to my function (I must know the name of the comboBox when I'm in the function).

Please advice... Thank you! Wish you a great day, Dolphin

1
  • After searching some similar questions, I tried the following: QtCore.QObject.connect(ComboJobType1_1, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(QString)")) ,lambda objName = "ComboJobType1_1": self.InputChanged(objName)) My function , for this try is: def InputChanged(self,objName): print objName And what I see in the print results is the selected value in my ComboBox and not the string I sent to my function... Please advice...... Thank you Commented Jun 27, 2012 at 10:05

3 Answers 3

3

ref https://eli.thegreenplace.net/2011/04/25/passing-extra-arguments-to-pyqt-slot

    button1.clicked.connect(lambda: self.on_button(1))
    button2.clicked.connect(lambda: self.on_button(2))

def on_button(self, n):
    print('Button {0} clicked'.format(n))

worked for me, tht gives it a simple lambda (turn it to funciton ref instead of execute ?

Sign up to request clarification or add additional context in comments.

Comments

0

You need to provide the emitting object ("from_object") and the slot handler ("self.my_handler"):

QtCore.QObject.connect(from_object, QtCore.SIGNAL("nameOfSignal(QString)"), self.my_handler)

1 Comment

Good morning, I managed to make it worked. Thanks anyway. I tried again the example with the lamda and now it's ok :)
0

Another way you can import partial function to pass arguments to slot function.

from functools import partial

QtCore.QObject.connect(ComboJobType1_1, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(QString)")) ,partial(self.InputChanged, "ComboJobType1_1"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.