1.使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数
# include "mainwindow.h"
# include "ui_mainwindow.h"
MainWindow :: MainWindow ( QWidget * parent)
: QMainWindow ( parent)
, ui ( new Ui:: MainWindow)
{
ui-> setupUi ( this ) ;
}
MainWindow :: ~ MainWindow ( )
{
delete ui;
}
void MainWindow :: on_loginbtn_clicked ( )
{
QString username = ui-> unedit-> text ( ) ;
QString password = ui-> pwedit-> text ( ) ;
if ( username== "admin" && password== "123456" )
{
qDebug ( ) << "登陆成功" ;
this -> close ( ) ;
} else {
qDebug ( ) << "登陆失败" ;
ui-> unedit-> setText ( "" ) ;
ui-> pwedit-> setText ( "" ) ;
}
}
void MainWindow :: on_closebtn_clicked ( )
{
this -> close ( ) ;
}
2.将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空
# include "mainwindow.h"
# include "ui_mainwindow.h"
MainWindow :: MainWindow ( QWidget * parent)
: QMainWindow ( parent)
, ui ( new Ui:: MainWindow)
{
ui-> setupUi ( this ) ;
}
MainWindow :: ~ MainWindow ( )
{
delete ui;
}
void MainWindow :: on_loginbtn_clicked ( )
{
QString username = ui-> unedit-> text ( ) ;
QString password = ui-> pwedit-> text ( ) ;
if ( username== "admin" && password== "123456" )
{
qDebug ( ) << "登陆成功" ;
this -> close ( ) ;
} else {
qDebug ( ) << "登陆失败" ;
ui-> unedit-> setText ( "" ) ;
ui-> pwedit-> setText ( "" ) ;
}
}