QT python connect passing arguments to function -



QT python connect passing arguments to function -

why code works:

from pyside.qtcore import * pyside.qtgui import * import sys functools import partial import pyside # code generated qt design class maindialog(qmainwindow, pyside.ui_mainwindow): def __init__(self, parent=none): super(maindialog,self).__init__(parent) self.setupui(self) self.connect(self.connect_buttom, signal("clicked()"), partial(self.get_fb_token, "aaaaa","bbbbbb")) def get_fb_token(self,email,passwd): print email print passwd app = qapplication(sys.argv) form = maindialog() form.show() app.exec_()

and prints aaaaa , bbbbb

but if change:

self.connect(self.connect_buttom, signal("clicked()"), partial(self.get_fb_token, "aaaaa","bbbbbb"))

to

self.connect(self.connect_buttom, signal("clicked()"), partial(self.get_fb_token, self.fb_username.text() ,self.fb_password.text()))

it not print introducing in text boxes fb_password , fb_username (it not crash not print if not sending both arguments function get_fb_token) ???

** took illustration from: http://www.blog.pythonlibrary.org/2013/04/10/pyside-connecting-multiple-widgets-to-the-same-slot/ im using qt , pyside

the partial object created when define connection, not when event triggered. means fb_username.text() called when connecting, print contents have set in designer.

to accomplish want have utilize function retrieves values when called. simplest solution be:

from pyside.qtcore import * pyside.qtgui import * import sys import pyside # code generated qt design class maindialog(qmainwindow, pyside.ui_mainwindow): def __init__(self, parent=none): super(maindialog,self).__init__(parent) self.setupui(self) # utilize new-style signals & slots! self.connect_buttom.clicked.connect(self.get_fb_token) def get_fb_token(self): email = self.fb_username.text() password = self.fb_password.text() print email print passwd app = qapplication(sys.argv) form = maindialog() form.show() app.exec_()

if, reason, don't want modify get_fb_token, can utilize lambda this:

self.connect_buttom.clicked.connect(lambda: self.get_fb_token(self.fb_username.text(), self.fb_password.text()))

python qt user-interface pyside

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -