Reputation: 167
I'm trying to use a dialog box in order to report an error to the user. It seems to be working if there is one error although when there are multiple it doesn't reopen when closed with the next error and instead crashes.
def errordialog(self, errormessage):
self.errordialog = QMessageBox()
self.errordialog.addButton("OK", 0)
self.errordialog.setText(errormessage)
self.errordialog.exec()
And this is the main program
def validate_data(data, regex):
if re.match(regex, data, re.VERBOSE):
error = False
else:
errormessage = "ERROR"
print("0")
self.errordialog(errormessage)
print("1")
self.errordialog.accept() # I added this in while trying to solve the issue
print("2")
error = True
return error
data = supplierid
regex = "[A-Z]$"
error = validate_data(data, regex)
print("3")
data = suppliername
regex = ".(1,50)$"
error = validate_data(data, regex)
print("4")
It prints 0,1,2,3,0 and then crashes
the error message is object QMessageBox is not callable
Upvotes: 1
Views: 127
Reputation: 109
After calling this line of code self.errordialog(errormessage)
, you go into the errordialog function. However, inside the errordialog function, you have redefined self.errordialog
so that it is of class QMessageBox instead of class function, so when it goes through the validation the second time, you attempt to call the QMessageBox, which does not work.
Simply changing the function or variable names will solve this problem.
Upvotes: 1