第一个界面头部的代码
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include<QLabel>
#include<QIcon>
#include<QLineEdit>
#include<QDebug>
class Widget : public QWidget
{
Q_OBJECT
signals:
void jump();
public slots://自定义登录按钮的信号处理函数
void butn1_slot();
public:
Widget(QWidget *parent = 0);
~Widget();
QLabel *label1;
QLabel *label2;
QLabel *label3;
QLineEdit *edit1;
QLineEdit *edit2;
QPushButton *butn1;
QPushButton *butn2;
};
#endif // WIDGET_H
第一个界面的代码
#include "widget.h"
void Widget::butn1_slot()
{
if(this->edit1->text() == "admin"&&this->edit2->text() == "123456")
{
qDebug()<<"登录成功";
emit jump();
this->close();//登陆成功后消失
}
else {
qDebug() << "账号或密码有误请重新输入";
}
}
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->setWindowIcon(QIcon(":/icon/logo.png"));
this->setWindowTitle("HQYJChat");
this->resize(700,750);
this->setStyleSheet("background-color:white");
label1 = new QLabel(this);
label1->setPixmap(QPixmap(":/icon/logo.png"));
label1->resize(700,260);
label1->setScaledContents(true);
label2 = new QLabel(this);
label2->setPixmap(QPixmap(":/icon/userName.jpg"));
label2->resize(30,30);
label2->move(170,320);
label2->setScaledContents(true);
label3 = new QLabel(this);
label3->setPixmap(QPixmap(":/icon/passwd.jpg"));
label3->resize(30,30);
label3->move(170,390);
label3->setScaledContents(true);
edit1 = new QLineEdit(this);
edit1->move(210,310);
edit1->resize(300,50);
edit1->setStyleSheet("border:none;border-bottom:2px solid lightblue");
edit1->setPlaceholderText("QQ号/微信/邮箱");
edit2 = new QLineEdit(this);
edit2->move(210,380);
edit2->resize(300,50);
edit2->setStyleSheet("border:none;border-bottom:2px solid lightblue");
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
butn1 = new QPushButton(this);
butn1->move(210,490);
butn1->resize(100,50);
butn1->setText("登录");
butn1->setIcon(QIcon(":/icon/login.png"));
connect(this->butn1,SIGNAL(clicked()),this,SLOT(butn1_slot()));//qt4版本的连接
butn2 = new QPushButton(this);
butn2->move(380,490);
butn2->resize(100,50);
butn2->setText("取消");
butn2->setIcon(QIcon(":/icon/cancel.png"));
connect(this->butn2,&QPushButton::clicked,this,&Widget::close);//qt5版本的连接
}
Widget::~Widget()
{
}
第二个界面cpp里的的代码
#include "second.h"
#include "ui_second.h"
void Second::jump()
{
this->show();
}
Second::Second(QWidget *parent) :
QWidget(parent),
ui(new Ui::Second)
{
ui->setupUi(this);
}
Second::~Second()
{
delete ui;
}
第二个界面头部的代码
#ifndef SECOND_H
#define SECOND_H
#include <QWidget>
namespace Ui {
class Second;
}
class Second : public QWidget
{
Q_OBJECT
public:
void jump();
public:
explicit Second(QWidget *parent = nullptr);
~Second();
private:
Ui::Second *ui;
};
#endif // SECOND_H