界面1.cpp
#include "myhomework.h"
myhomework::myhomework(QWidget *parent)
: QMainWindow(parent)
{
//设置主窗口
this->setFixedSize(530,360);
this->setWindowIcon(QIcon("D:/C++/QT/day1/icon_nhgbq8i4bf/QQ.png"));
this->setWindowTitle("QQ");
//设置label头像
lab=new QLabel(this);
lab->resize(530,150);
lab->setScaledContents(true);
lab->setPixmap(QPixmap("D:/C++/QT/day1/icon_nhgbq8i4bf/123.gif"));
//设置label账号密码
lab1=new QLabel(this);
lab1->move(130,170);
lab1->resize(20,20);
lab1->setScaledContents(true);
lab1->setPixmap(QPixmap("D:/C++/QT/day1/icon_nhgbq8i4bf/denglu.png"));
lab2=new QLabel(this);
lab2->move(130,200);
lab2->resize(lab1->size());
lab2->setScaledContents(true);
lab2->setPixmap(QPixmap("D:/C++/QT/day1/icon_nhgbq8i4bf/denglumima.png"));
//设置lineedit
edit=new QLineEdit(this);
edit->move(160,170);
edit->resize(260,23);
edit->setPlaceholderText("QQ号码/手机/邮箱");
edit1=new QLineEdit(this);
edit1->move(160,200);
edit1->resize(edit->size());
edit1->setPlaceholderText("密码");
//设置checkbox
box=new QCheckBox("自动登录",this);
box->move(130,230);
box1=new QCheckBox("记住密码",this);
box1->move(230,230);
//设置pushbutton
btn=new QPushButton("登录",this);
btn->move(250,280);
btn->resize(70,30);
btn->setIcon(QIcon("D:/C++/QT/day1/icon_nhgbq8i4bf/denglu_1.png"));
btn1=new QPushButton("退出",this);
btn1->move(370,280);
btn1->resize(btn->size());
btn1->setIcon(QIcon("D:/C++/QT/day1/icon_nhgbq8i4bf/quxiao.png"));
//按下登录按钮,使用qt5连接自定义的槽函数
connect(this->btn,&QPushButton::clicked,
this,&myhomework::btn_slot);
//按下退出按钮,使用qt5连接自定义的槽函数
connect(this->btn1,&QPushButton::clicked,
this,&myhomework::btn1_exit);
}
void myhomework::btn_slot()
{
int ret;
//登录成功
if(edit->text()=="admin" && edit1->text()=="123456")
{
QMessageBox box( //函数名
QMessageBox::NoIcon, //消息对话框图标
"登录成功", //对话标题框
"登录成功", //对话框文本内容
QMessageBox::Ok, //提供的按钮
this); //默认按钮
ret=box.exec(); //执行exec函数
emit jump(); //跳转
this->close(); //关闭主界面
}
//登录失败
else {
ret=QMessageBox::warning( //函数名
this, //父组件
"登录失败", //对话标题框
"账号密码不匹配,是否需要重新登录", //对话框文本内容
QMessageBox::Ok|QMessageBox::Cancel, //提供的按钮
QMessageBox::Ok); //默认按钮
//清空文本框
if(ret==QMessageBox::Ok)
{
edit->clear();
edit1->clear();
}
}
}
//退出
void myhomework::btn1_exit()
{
int ret=QMessageBox::question( //函数名
this, //父组件
"QQ", //对话标题框
"是否退出登录", //对话框文本内容
QMessageBox::Yes|QMessageBox::No, //提供的按钮
QMessageBox::No); //默认按钮
if(ret==QMessageBox::Yes)
{
this->close();
}
}
myhomework::~myhomework()
{
}
界面2.cpp
#include "second.h"
#include "ui_second.h"
second::second(QWidget *parent) :
QWidget(parent),
ui(new Ui::second)
{
ui->setupUi(this);
}
second::~second()
{
delete ui;
}
void second::jump_slot()
{
this->show(); //展示界面
}