#ifndef BUTTON_H
#define BUTTON_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QString>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class button; }
QT_END_NAMESPACE
class button : public QWidget
{
Q_OBJECT
signals:
void my_jump();
public slots:
void my_slot();
void my_slot1();
public:
button(QWidget *parent = nullptr);
~button();
private:
Ui::button *ui;
QPushButton *btn1;
QPushButton *btn2;
QLineEdit * edit1;
QLineEdit * edit2;
};
#endif // BUTTON_H
#ifndef FORM_H
#define FORM_H
#include <QWidget>
namespace Ui {
class Form;
}
class Form : public QWidget
{
Q_OBJECT
public:
explicit Form(QWidget *parent = nullptr);
~Form();
public:
void jump_slot();
private:
Ui::Form *ui;
};
#endif // FORM_H
#include "button.h"
#include "ui_button.h"
void button::my_slot()
{
if("admin"==edit1->text()&&edit2->text()=="123456")
{
qDebug()<<"登录成功";
emit my_jump();
this->close();
}else {
qDebug()<<"登录失败";
edit2->clear();
}
}
void button::my_slot1()
{
this->close();
}
button::button(QWidget *parent)
: QWidget(parent)
, ui(new Ui::button)
{
ui->setupUi(this);
this->resize(560,450);
this->setWindowIcon(QIcon(":/icon/wodepeizhenshi.png"));
this->setWindowTitle("鹏哥快聊");
QLabel *lab1 = new QLabel(this);
lab1->resize(560,200);
lab1->setPixmap(QPixmap("D:\\嵌入式\\QT\\day1\\icon\\logo.png"));
lab1->setScaledContents(true);
QLabel *lab2 = new QLabel(this);
lab2->resize(40,40);
lab2->move(80,240);
lab2->setPixmap(QPixmap("D:\\嵌入式\\QT\\day1\\icon\\userName.jpg"));
lab2->setScaledContents(true);
QLabel *lab3 = new QLabel(this);
lab3->resize(40,40);
lab3->move(lab2->x(),lab2->y()+80);
lab3->setPixmap(QPixmap("D:\\嵌入式\\QT\\day1\\icon\\passwd.jpg"));
lab3->setScaledContents(true);
edit1 = new QLineEdit(this);
edit1->resize(280,40);
edit1->move(lab2->x()+80,lab2->y());
edit1->setPlaceholderText("QQ号码/手机/邮箱");
edit2 = new QLineEdit(this);
edit2->resize(280,40);
edit2->move(lab3->x()+80,lab3->y());
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
btn1 = new QPushButton(QIcon("D:\\嵌入式\\QT\\day1\\icon\\login.png"),"登录",this);
btn1->resize(100,40);
btn1->move(edit2->x()+100,edit2->y()+80);
btn2 = new QPushButton(QIcon("D:\\嵌入式\\QT\\day1\\icon\\cancel.png"),"取消",this);
btn2->resize(100,40);
btn2->move(btn1->x()+110,btn1->y());
connect(btn1,&QPushButton::clicked,this,&button::my_slot);
connect(btn2,SIGNAL(clicked()),this,SLOT(close()));
}
button::~button()
{
delete ui;
}
#include "form.h"
#include "ui_form.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
}
Form::~Form()
{
delete ui;
}
void Form::jump_slot()
{
this->show();
}
#include "button.h"
#include "form.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
button w;
w.show();
Form f;
QObject::connect(&w,&button::my_jump,&f,&Form::jump_slot);
return a.exec();
}