表单输入验证,多个焦点问题
我在尝试验证 QT4 中的某些输入时遇到问题。
我有一个带有 2 个文本编辑字段的表单。当一个字段失去焦点时,我希望它检查该字段是否为空,如果是,则提醒用户。
这是我的代码:
void newconsole::on_nameEdit_lostFocus()
{
if (this->ui->nameEdit->text().size() < 1)
{
QMessageBox b;
b.setText("Name must be longer than 0 characters.");
b.setIcon(QMessageBox::Information);
b.setStandardButtons(QMessageBox::Ok);
b.show();
}
}
void newconsole::on_fileextensionEdit_lostFocus()
{
if (this->ui->fileextensionEdit->text().size() < 1)
{
QMessageBox b;
b.setText("File extension must be longer than 0 characters.");
b.setIcon(QMessageBox::Information);
b.setStandardButtons(QMessageBox::Ok);
b.show();
}
}
我的问题是,当我运行表单并失去对第一个 textEdit (nameEdit) 的焦点时,我从两个信号中都得到一个 MessageBox。有什么建议吗?
I am having an issue trying to validate some input in QT4.
I have a form with 2 textEdit fields. When one field loses focus, I want it to check if the field is empty, and if so, alert the user.
Here is my code:
void newconsole::on_nameEdit_lostFocus()
{
if (this->ui->nameEdit->text().size() < 1)
{
QMessageBox b;
b.setText("Name must be longer than 0 characters.");
b.setIcon(QMessageBox::Information);
b.setStandardButtons(QMessageBox::Ok);
b.show();
}
}
void newconsole::on_fileextensionEdit_lostFocus()
{
if (this->ui->fileextensionEdit->text().size() < 1)
{
QMessageBox b;
b.setText("File extension must be longer than 0 characters.");
b.setIcon(QMessageBox::Information);
b.setStandardButtons(QMessageBox::Ok);
b.show();
}
}
My issue is that when I run the form and lose focus on the first textEdit (nameEdit) I get a MessageBox from BOTH signals. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是:
希望这有帮助,问候
my guess would be:
hope this helps, regards