新的项目注释
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)//构造函数的定义
: QWidget(parent) //调用父类的有参构造
, ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget() //析构函数的定义
{
delete ui;
}
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv); //实例化Qaoolication类的对象,为了调用exec函数
Widget w; //实例化窗口对象,调用show函数
w.show();
return a.exec();
}
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; } //申明UI界面中的命名空间
QT_END_NAMESPACE
class Widget : public QWidget //继承自Qwidget的类
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr); //构造函数,默认参数为NULLPTR
~Widget(); //析构函数
private:
Ui::Widget *ui; //ui指针,指向ui文件中的成员
};
#endif // WIDGET_H
完善登录窗口
#ifndef SECONT_H
#define SECONT_H
#include <QWidget>
namespace Ui {
class secont;
}
class secont : public QWidget
{
Q_OBJECT
public:
explicit secont(QWidget *parent = nullptr);
~secont();
private:
Ui::secont *ui;
public slots:
void jumpslots();
};
#endif // SECONT_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QtDebug> //打印输出
#include <QIcon>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
class Widget : public QWidget
{
Q_OBJECT
public:
QPushButton *btn1,*btn2;
QLineEdit *line1,*line2;
QLabel *lab1,*lab2,*lab3;
Widget(QWidget *parent = nullptr);
~Widget();
public slots:
void my_slot1();
void check();
signals:
void mysignal();
void jump();
};
#endif // WIDGET_H
#include "widget.h"
#include "secont.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
secont s;
w.show();
QObject::connect(&w,&Widget::jump,&s,&secont::jumpslots);
return a.exec();
}
#include "secont.h"
#include "ui_secont.h"
secont::secont(QWidget *parent) :
QWidget(parent),
ui(new Ui::secont)
{
ui->setupUi(this);
}
secont::~secont()
{
delete ui;
}
void secont::jumpslots()
{
this->show();
}
#include "widget.h"
void Widget::my_slot1()
{
this->close();
}
void Widget::check()
{
if(this->line1->text()=="admin"&&this->line2->text()=="123456")
{
qDebug()<<"登录成功"<<endl;
this->close();
emit jump();
}
else
{
qDebug()<<"登录失败"<<endl;
this->line2->clear();
this->line1->clear();
}
}
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->setFixedSize(600,400);
this->setWindowOpacity(0.8);
this->setWindowIcon(QIcon(":/icon/1.png"));
this->setWindowTitle("聊聊");
this->setStyleSheet("background-color:pink");
/***************************************/
this->lab1 = new QLabel(this);
lab1->setPixmap(QPixmap(":/icon/gif.gif"));
lab1->resize(600,150);
lab1->setScaledContents(true);
/*****************************************/
this->lab2 = new QLabel(this);
lab2->setPixmap(QPixmap(":/icon/userName.jpg"));
lab2->setScaledContents(true);
lab2->resize(40,40);
lab2->move(180,180);
/*****************************************/
this->lab3 = new QLabel(this);
lab3->setPixmap(QPixmap(":/icon/2.jpg"));
lab3->setScaledContents(true);
lab3->resize(40,40);
lab3->move(180,230);
/***************************************/
this->line1 = new QLineEdit(this);
line1->setPlaceholderText("账号");
line1->resize(200,40);
line1->move(240,180);
/******************************************/
this->line2 = new QLineEdit(this);
line2->setPlaceholderText("密码");
line2->setEchoMode(QLineEdit::Password);
line2->resize(200,40);
line2->move(240,230);
/*************************************/
this->btn1 = new QPushButton(QIcon(":/icon/login.png"),\
"登录",this);
btn1->resize(80,40);
btn1->move(240,280);
//btn1->setStyleSheet("border-radius:10px");
connect(btn1,&QPushButton::clicked,this,&Widget::check);
/*************************************/
this->btn2 = new QPushButton(QIcon(":/icon/cancel.png"),\
"取消",this);
btn2->resize(80,40);
//btn2->setStyleSheet("border-radius:10px");
btn2->move(350,280);
this->connect(btn2,SIGNAL(clicked()),this,SLOT(my_slot1()));
//disconnect(btn2,SIGNAL(clicked()),this,SLOT(my_slot1()));
}
Widget::~Widget()
{
}