Qt 3.3 - QLineEdit::lostFocus() firing on app lost focus
Not sure if it matters that I'm using Qt 3.3 instead of 4.x for this issue, but I'm working on a legacy application. I have a dialog that I has a couple QLineEdit boxes and OK and Cancel buttons. I have connected the QLineEdit::lostFocus() signal for both edit boxes to their own separate handler where I check the content to make sure it has correct format before continuing. If not correct format, I pop up a QMessageBox() to inform the user of the details of the error and give them an OK button to close the error dialog. Everything works fine, but when I click on the OK button when there is incorrect input, the QMessageBox() is invoked, which is correct, but the OK button then proceeds to close the dialog, which is incorrect.
So I looked into having the OK button also invoke the same check before choosing whether to close or not, and that caused a dialog to pop up as a result of both the OK and edit box lost focus signals running the check. Changed that so that the OK button only checks but doesn't put up the dialog, and only closes its window on good input format. So now it's working fine, but I would love to hear about a way to do this more elegantly.
The problem I'm running into now is that if another application comes into focus while one of the edit boxes is in focus and has incorrectly formatted input, the QMessageBox will pop up, which I definitely don't want it to do, and then, when it is put away, somehow the lost focus signal goes off again for the same edit box, and the QMessageBox is shown again, and this keeps happening, causing me to have to go to the Windows Task Manager to kill the application.
Can anyone suggest a better way of doing what I'm doing? Or a way for my edit box check function to detect that the reason for the loss of focus was because another app came into focus, so that it won't then put up the QMessageBox? I've run out of ideas on this one.
Thanks for your help...