I am using a partial function to pass a value to a function argument, on a click of a QPushButton.
self.SearchButton1 = QPushButton("Search")
self.SearchStudent1 = QLineEdit()
Below is how it is connected:
self.connect(self.SearchButton1, SIGNAL("clicked()"),
partial(self.Searching, self.SearchStudent1.text()))
The called function is as below:
def Searching(self, num):
print self.SearchStudent1.text()
print num
I am not sure why num is not getting printed, whereas self.SearchStudent1.text() gets printed correctly on the press of the 'Search' button.
Please suggest if I am missing anything.
EDIT:
I can anyhow pass the QLineEdit object using partial function and work with it:
self.connect(self.SearchButton1, SIGNAL("clicked()"),
partial(self.Searching, self.SearchStudent1))
def Searching(self, num):
print self.SearchStudent1.text()
print num.text() # works fine
The partial function will cache the arguments passed to it. So if the line-edit is empty when the signal is connected, an empty string will always be sent to the called method. (It's always a good idea to use
reprwhen debugging withprint, so that you can easily see output values like""orNone).If you want the current text is be sent to the slot when the button is clicked, you can use a
lambdafunction, like this:Or more simply: