1、main.cpp
#include "widget.h"
#include "second.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Second b;
QObject::connect(&w,&Widget::jump,&b,&Second::jump_slot);
return a.exec();
}
2、second.cpp
#include "second.h"
#include "ui_second.h"
Second::Second(QWidget *parent) :
QWidget(parent),
ui(new Ui::Second)
{
ui->setupUi(this);
}
Second::~Second()
{
delete ui;
}
void Second::jump_slot(){
this->show();
}
3、widget.cpp
#include "widget.h"
void Widget::my_slot(){
if(edit_usr->text()=="admin"&&edit_pd->text()=="123456"){ //账号匹配
Widget::jump(); //登录成功,跳转
//this->hide();
qDebug() << "登录成功";
}else{
qDebug() << "登录失败";
}
}
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->resize(600,400);
this->setWindowIcon(QIcon(":/icon/R-C.png"));
this->setWindowTitle("夸克聊天室");
//logo框
lab1=new QLabel(this);
lab1->resize(600,180);
lab1->setPixmap(QPixmap(":/icon/quark.jpg"));
lab1->setScaledContents(true);
//用户头像
lab2=new QLabel(this);
lab2->resize(40,40);
lab2->move(180,200);
lab2->setPixmap(QPixmap(":/icon/usr.png"));
lab2->setScaledContents(true);
//账号框
edit_usr=new QLineEdit(this);
edit_usr->move(230,210);
edit_usr->setPlaceholderText("账号");
//密码图像
lab3=new QLabel(this);
lab3->resize(35,35);
lab3->move(180,250);
lab3->setPixmap(QPixmap(":/icon/pd.png"));
lab3->setScaledContents(true);
//密码框
edit_pd=new QLineEdit(this);
edit_pd->move(230,260);
edit_pd->setPlaceholderText("密码");
edit_pd->setEchoMode(QLineEdit::Password);
//登录按钮
btn_up=new QPushButton(QIcon(":/icon/denglu_1.png"),"登录",this);
btn_up->move(180,310);
connect(btn_up,SIGNAL(clicked()),this,SLOT(my_slot())); //将登录点击与登录触发槽函数绑定
//取消按钮
btn_cancle=new QPushButton(QIcon(":/icon/quxiao.png"),"取消",this);
btn_cancle->move(305,310);
connect(btn_cancle,&QPushButton::clicked,this,&Widget::close);
}
Widget::~Widget()
{
}