python - PyQt4 User Input Validation - QlineEdit -


i'm having little trouble understanding input validation pyqt4. first gui application , first time working pyqt4 framework. i've been reading through class reference , looks preferred way text validation through qregularexpression class seems excessive simple input validation.

i have method in register user class adds user sqlite database. created signal qlineedits connects method validates text. sql input works fine reason input validation not. not pull error. messageboxes not pop up. understand created 1 signal testing.

def newuser(self):                 #this method adds new user login database , displays pop window confirming entry     c.execute("insert logins(usernames, passwords)values(?,?)", (self.useredit.text(), self.passedit.text())) #sql query inserts entries line edit , pass edit database     c.commit() #save database changes     self.connect(self.useredit, qtcore.signal("textchanged()"), self.validtext)   def validtext(self):     if len(self.useredit.text()) < 4:         if len(self.passedit.text()) < 4:             self.msg = qtgui.qmessagebox.information(self, 'message', 'not enough characters!', qtgui.qmessagebox.ok)                else:             self.msg = qtgui.qmessagebox.information(self, 'message', 'user added successfully', qtgui.qmessagebox.ok) 

semantically know makes sense can't figure out went wrong syntactically. can tell me if there concept should looking @ besides using len?

thanks in advance!

i hope understand question, got qlineedit somewhere in app. , want stop users enter "strange" characters like: ~!@#$#%)(& ...and on, read in question use input gathered user send in database, in case if database need avoid sending again "strange" characters, well... if case then, made quick app. show how can avoid here code:

from pyqt4.qtcore import * pyqt4.qtgui import * import sys   class main_window(qdialog):     def __init__(self):         qdialog.__init__(self)          # create qlineedit         le_username = qlineedit(self)         le_username.setplaceholdertext("enter username")         le_password = qlineedit(self)         le_password.setplaceholdertext("enter password")          # create qlabel         lb_username = qlabel("username: ")         lb_password = qlabel("password: ")          # adding layout         self.setlayout(qvboxlayout())           # adding widgets layout         self.layout().addwidget(lb_username)         self.layout().addwidget(le_username)           self.layout().addwidget(lb_password)         self.layout().addwidget(le_password)           #!! regex implementation !!         # more details regex search on google: regex rules or similar          reg_ex = qregexp("[a-z-a-z_]+")         le_username_validator = qregexpvalidator(reg_ex, le_username)         le_username.setvalidator(le_username_validator)         #!! regex implementation end !!           #.......         self.setminimumwidth(200)         self.setwindowtitle("regex validator in python qt framework")  app = qapplication(sys.argv) dialog = main_window() dialog.show() sys.exit(app.exec_()) 

i hope out figure how filter user input in qlineedit, or anywhere got user input based on characters...


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -