[Solved]login form enter key not working
-
wrote on 29 Aug 2012, 04:53 last edited by
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] -
wrote on 29 Aug 2012, 05:17 last edited by
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
-
wrote on 29 Aug 2012, 06:02 last edited by
It didnt work i tried sam, I am using QMainWindow...Is there any way to make it work in qmainwindow or should i have to change to qdialog...?
-
wrote on 29 Aug 2012, 06:20 last edited by
It works for QDialog as per the documentation. In order to work for the QMainWindow you can override/handle the keyPressEvent().
-
wrote on 29 Aug 2012, 09:00 last edited by
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??
}
}@ -
wrote on 30 Aug 2012, 10:50 last edited by
thanks jeroentje & sam
-
wrote on 30 Aug 2012, 11:42 last edited by
Did you get it working. If yes then Kindly edit your first post and add [Solved] to the title.
Happy Coding!!!!
-
wrote on 31 Aug 2012, 09:07 last edited by
Ya working sam, used qdialog....
-
wrote on 19 Nov 2012, 04:30 last edited by
Dear Jeroentje,
Would you mind to share the QYourDialog code?
Thanks in advance.