#ifndef FORM_H
#define FORM_H
#include
namespace Ui {
class Form;
}
class Form : public QWidget
{
Q_OBJECT
public:
explicit Form(QWidget *parent = nullptr);
~Form();
public slots:
void sw();
private:
Ui::Form *ui;
};
#endif // FORM_H
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
#include
class Widget : public QWidget
{
Q_OBJECT
signals:
void jump();
public:
Widget(QWidget *parent = nullptr);
QLabel *p;
QLabel *q;
QLabel *w;
QLineEdit *e1;
QPushButton *r1;
QLineEdit *e2;
QPushButton *r2;
~Widget();
public slots:
void fun_1();
void fun_2();
};
#endif // WIDGET_H
#include "form.h"
#include "ui_form.h"
#include
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
QLabel *p=new QLabel("登录成功",this);
}
void Form::sw()
{
this->show();
}
Form::~Form()
{
delete ui;
}
#include "widget.h"
#include
#include
#include
#include
#include
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->setWindowTitle("鹏哥快聊");
this->setWindowIcon(QIcon(":/new/prefix1/wodepeizhenshi.png"));
this->resize(490,410);
p=new QLabel(this);
p->setPixmap(QPixmap(":/new/prefix1/logo.png"));
p->move(0,0);
p->resize(510,180);
q=new QLabel(this);
q->setPixmap(QPixmap(":/new/prefix1/userName.jpg"));
q->resize(40,30);
q->move(80,220);
q->setScaledContents(true);
w=new QLabel(this);
w->setPixmap(QPixmap(":/new/prefix1/passwd.jpg"));
w->resize(40,30);
w->move(80,290);
w->setScaledContents(true);
e1=new QLineEdit(this);
e1->setPlaceholderText("QQ号码/手机/邮箱");
e1->resize(200,40);
e1->move(160,220);
e2=new QLineEdit(this);
e2->setPlaceholderText("密码");
e2->resize(200,40);
e2->move(160,290);
e2->setEchoMode(QLineEdit::Password);
r1=new QPushButton("登录",this);
r1->resize(90,40);
r1->move(240,360);
r1->setIcon(QIcon(":/new/prefix1/login.png"));
r2=new QPushButton("取消",this);
r2->resize(90,40);
r2->move(345,360);
r2->setIcon(QIcon(":/new/prefix1/cancel.png"));
connect(r1,&QPushButton::clicked,this,&Widget::fun_1);
}
void Widget::fun_1()
{
if(e1->text()=="admin"&&e2->text()=="123456")
{
qDebug()<<"登录成功";
emit jump();
this->close();
}
else
{
qDebug()<<"登录失败";
e2->setText("");
}
}
void Widget::fun_2()
{
}
Widget::~Widget()
{
}
#include "widget.h"
#include "form.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Form e;
QObject::connect(&w,&Widget::jump,&e,&Form::sw);
return a.exec();
}
![8.31作业_第1张图片](http://img.e-com-net.com/image/info8/c7f83bdb8700472e931bb915b2ed9eb1.jpg)
![8.31作业_第2张图片](http://img.e-com-net.com/image/info8/b2517ce7d36e40ae817664b37d873eaf.jpg)
![8.31作业_第3张图片](http://img.e-com-net.com/image/info8/eed14806286b4e9a87d3ad7725fde04e.jpg)