I'm having a little trouble understanding input validation with PyQt4. This is my first GUI application and first time working with the PyQt4 framework. I've been reading through the Class reference and it looks like the preferred way to do text validation would be through the QRegularExpression class but that seems excessive for some simple input validation.
I have a method in my register user class that adds a user into a sqlite database. I also created a signal for the QlineEdits that connects to a method that validates the text. The SQL input works just fine but for some reason the input validation does not. This does not pull an error. The MessageBoxes just do not pop up. I understand that I only created one SIGNAL but this was just for testing.
def newUser(self): #This method adds a new user into the login database and displays a pop up window confirming the entry
c.execute("INSERT INTO logins(usernames, passwords)VALUES(?,?)", (self.userEdit.text(), self.passEdit.text())) #sql query inserts entries from line edit and pass edit into 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 I know this makes sense but I can't figure out where I went wrong syntactically. Can someone tell me if there is a another concept I should be looking at besides using len?
Thanks in advance!