cpp
复制代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//使用qt4将右上角x设置关闭触发
connect(btn2,SIGNAL(clicked()),this,SLOT(close_slot()));
//使用qt5将快速登录按钮设置触发事件
connect(btn1,&QPushButton::clicked,this,&MyWidget::log_slot);
}
void MyWidget::close_slot()
{
this->close();
}
void MyWidget::log_slot(){
//比较账号和密码
if(QString::compare("admin",edt1->text())==0 && QString::compare("123456",edt2->text())==0){
qDebug()<<"登录成功";
this->close();
}else {
edt2->clear();
qDebug()<<"登录失败";
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_closebtn_clicked()
{
this->close();
}