window.cpp
#include "window.h"
#include<QDebug>
#include<QIcon>
Window::Window(QWidget *parent) //构造函数的定义: QWidget(parent) //显性调用父类的构造函数
{//this->resize(430,330);this->resize(QSize(800,600));// this->setMaximumSize(430,330);// this->setMinimumSize(430,330);this->setFixedSize(430,330);// 设置尺寸最值//窗口标题this->setWindowTitle("WeChat");//窗口iconthis->setWindowIcon(QIcon(":/icon/111.png"));//设置背景色this->setStyleSheet("background-color:skyblue;");//设置窗口透明度this->setWindowOpacity(1);//无参构造bt1 =new QPushButton;//给组件指定父组件,让其依附于界面bt1->setParent(this);//设置组件文本内容bt1->setText("开始");this->setFixedSize(430,330);//设置按钮组件的大小bt1->resize(QSize(50,30));//移动组件位置bt1->move(200,290);//设置样式表bt1->setStyleSheet("background-color:red");bt1->setIcon(QIcon("E:\\c\\qt1\\111.png"));//2.构造一个按钮bt2 = new QPushButton(this);bt2->setText("取消");bt2->resize(bt1->size());bt2->move(300,290);// bt2->setStyleSheet("background-color:blue");// bt2->setEnabled(false);bt2->setIcon(QIcon("E:\\c\\qt1\\111.png"));//3.创建图标bt3 =new QLabel(this);bt3->resize(bt1->size());bt3->move(100,170);bt3->setPixmap(QString("E:\\c\\qt1\\111.png"));//设置 内容自适应bt3->setScaledContents(true);//4.创建图标bt4 =new QLabel(this);bt4->resize(bt1->size());bt4->move(100,220);bt4->setPixmap(QString("E:\\c\\qt1\\222.png"));//设置 内容自适应bt4->setScaledContents(true);/***********************************/ed1 =new QLineEdit(this);//ed1->setText(""); //设置编辑器中的文本//设置占位文本ed1->setPlaceholderText("密码:");//设置尺寸ed1->resize(180,30);//移动位置ed1->move(bt4->x()+60,bt4->y());ed1->setPlaceholderText("密码:");ed1->setEchoMode(QLineEdit::Password);//2.构造一个行编辑器,构造时给定父,以及文本内容ed2 = new QLineEdit(this);ed2->resize(180,30);ed2->move(bt3->x()+60,bt3->y());ed2->setPlaceholderText("账号 /手机 /邮箱...");/***********************************/la1 =new QLabel(this);la1 ->resize(430,140);la1->setPixmap(QString("E:\\c\\qt1\\222.png"));//设置 内容自适应la1->setScaledContents(true);connect(this->bt1,&QPushButton::clicked,this,&Window::bt1_clicked);//connect(this,&Window::my_signal,[&](){this->close();});//使用qt4连接,connect(bt2,SIGNAL(clicked()),this,SLOT(close()));}
Window::~Window()
{
}void Window::bt1_clicked()
{qDebug() << Window::ed2->text();qDebug() << Window::ed1->text();if(Window::ed2->text()=="473667977"){if(Window::ed1->text()=="123456"){qDebug()<<"登录成功";emit jump();emit my_signal();}else{qDebug()<<"密码错误";Window::ed1->setText("");}}else{qDebug()<<"账号错误";Window::ed1->setText("");Window::ed2->setText("");}
}
main.cpp
#include "window.h"
#include"form.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Window w;w.show();Form f;QObject::connect(&w,&Window::jump,&f,&Form::jump_slot);return a.exec();
}
form.cpp
#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();
}