I woudn't use the editingFinished signal to validate.
If you want to validate only when the OK button is clicked, do it like this:
MyDialog
::MyDialog(QWidget *parent
) :{
// ...
connect(pushButton_OK, SIGNAL(clicked()), this, SLOT(validate()));
connect(pushButton_Cancel, SIGNAL(clicked()), this, SLOT(reject()));
}
void MyDialog::validate()
{
if (lineEdit->text() != "Valid data")
{
QMessageBox::critical(this, tr
("Invalid Data"), tr
("You entered invalid data"));
return;
}
accept();
}
MyDialog::MyDialog(QWidget *parent) :
QDialog(parent),
{
// ...
connect(pushButton_OK, SIGNAL(clicked()), this, SLOT(validate()));
connect(pushButton_Cancel, SIGNAL(clicked()), this, SLOT(reject()));
}
void MyDialog::validate()
{
if (lineEdit->text() != "Valid data")
{
QMessageBox::critical(this, tr("Invalid Data"), tr("You entered invalid data"));
return;
}
accept();
}
To copy to clipboard, switch view to plain text mode
Bookmarks