[Solved]login form enter key not working
-
Hi,
I have a login form, when user enters user name and password it will open second form..but wen i click enter nothing happens...when i click enter key it should go to this function..how to do it..please help
[CODE]
void login::on_ok_clicked()
{
if(ui->u_name->text()=="a" && ui->pwd->text()=="a")
{
//hide();
qWarning("Login Sucessful");
}
else
{
ui->statusBar->showMessage("Login Failure");
}
}
[/CODE] -
In order to achieve that you can try
@okButton->setDefault(true)@
check "QPushButton::setDefault()":http://doc.qt.nokia.com/4.7-snapshot/qpushbutton.html#default-prop
Edit: This works for a QDialog
-
It might be a good idea to use a QDialog to handle this. Then give the dialog a parent (your main window). You MainWindow file will then be must shorter (if you make the dialog in it's own cpp file etc). In the MainWindow you won't be bothered by the signals (Done in the QDialog) etc.
Might look like this:
@
QYourDialog LoginBox = new QYourDialog;
if (LoginBox->exec() == QDialog::Accepted)
{
if (LoginBox->u_name->text() == "a")
{
// Oke??
}
else
{ // Wrong??
}
}@ -
Dear Jeroentje,
Would you mind to share the QYourDialog code?
Thanks in advance.