QComboBox is connected to a function using following syntax:
JavaScript
x
2
1
myComboBox.activated.connect(self.myFunction )
2
But I need to be able to send the arguments from ComboBox to myFunction(). But if I use:
JavaScript
1
2
1
myComboBox.activated.connect(self.myFunction(myArg1, myArg2 )
2
I am getting
JavaScript
1
2
1
TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'
2
What syntax needs to be used to connect a QComboBox to a function that is able to receive arguments sent from Comobobox?
EDITED LATER:
Here is the code resulting an TypeError:
connect() slot argument should be a callable or a signal, not 'NoneType'
JavaScript
1
29
29
1
from PyQt4 import QtCore, QtGui
2
import sys
3
4
class MyClass(object):
5
def __init__(self, arg):
6
super(MyClass, self).__init__()
7
self.arg = arg
8
9
class myWindow(QtGui.QWidget):
10
def __init__(self, parent=None):
11
super(myWindow, self).__init__(parent)
12
13
self.comboBox = QtGui.QComboBox(self)
14
self.comboBox.addItems([str(x) for x in range(3)])
15
16
self.myObject=MyClass(id(self) )
17
18
self.comboBox.activated.connect(self.myFunction(self.myObject, 'someArg'))
19
20
def myFunction(self, arg1=None, arg2=None):
21
print 'nt myFunction(): ', type(arg1),type(arg2)
22
23
if __name__ == "__main__":
24
app = QtGui.QApplication(sys.argv)
25
app.setApplicationName('myApp')
26
dialog = myWindow()
27
dialog.show()
28
sys.exit(app.exec_())
29
Advertisement
Answer
After I posted a question Stachoverflow suggested a link which explained a lot. Here is the answer:
JavaScript
1
30
30
1
from PyQt4 import QtCore, QtGui
2
3
class MyClass(object):
4
def __init__(self, arg):
5
super(MyClass, self).__init__()
6
self.arg = arg
7
8
class myWindow(QtGui.QWidget):
9
def __init__(self, parent=None):
10
super(myWindow, self).__init__(parent)
11
12
self.comboBox = QtGui.QComboBox(self)
13
self.comboBox.addItems([str(x) for x in range(3)])
14
15
self.myObject=MyClass(id(self) )
16
17
slotLambda = lambda: self.indexChanged_lambda(self.myObject)
18
self.comboBox.currentIndexChanged.connect(slotLambda)
19
20
@QtCore.pyqtSlot(str)
21
def indexChanged_lambda(self, string):
22
print 'lambda:', type(string), string
23
24
if __name__ == "__main__":
25
app = QtGui.QApplication(sys.argv)
26
app.setApplicationName('myApp')
27
dialog = myWindow()
28
dialog.show()
29
sys.exit(app.exec_())
30