widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);//去掉头部this->setWindowFlag(Qt::FramelessWindowHint);//去掉组件空白部分this->setAttribute(Qt::WA_TranslucentBackground);//手动连接,将登录框中的取消按钮使用qt4版本连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(my_slot()));//将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为admin,密码是否为123456connect(ui->pushButton,&QPushButton::clicked,this,&Widget::my_slot2);
}
//槽函数的实现
void Widget::my_slot()
{this->close();
}
//槽函数的实现2
void Widget::my_slot2()
{QString name=this->ui->lineEdit->text();QString pwd=this->ui->lineEdit_2->text();if(name=="admin"&&pwd=="123456"){qDebug("success");this->close();emit my_jump();}else{qDebug("failed");this->ui->lineEdit_2->clear();}
}
Widget::~Widget()
{delete ui;
}
success.cpp
#include "success.h"
#include "ui_success.h"success::success(QWidget *parent) :QWidget(parent),ui(new Ui::success)
{ui->setupUi(this);
}success::~success()
{delete ui;
}
//界面2槽函数的实现
void success::myslot()
{this->show();
}
main.cpp
#include "widget.h"
#include "success.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();success s;QObject::connect(&w,&Widget::my_jump,&s,&success::myslot);return a.exec();
}