1、登录系统添加跳转
widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
//设置窗口固定尺寸
this->setFixedSize(500,400);
//设置窗口标题
this->setWindowTitle("登录系统");
//设置窗口图标
this->setWindowIcon(QIcon("D:\\QT\\hqyj\\QT\\icon\\QQ.png"));
//标签
QLabel *lab1 = new QLabel(this);
lab1->resize(500,150);
lab1->setPixmap(QPixmap("D:\\QT\\hqyj\\QT\\icon\\logo.png"));
lab1->move(0,0);
lab1->setScaledContents(true);
QLabel *lab2 = new QLabel(this);
lab2->resize(60,40);
lab2->setPixmap(QPixmap("D:\\QT\\hqyj\\QT\\icon\\denglu.png"));
lab2->move(130,150);
lab2->setScaledContents(true);
QLabel *lab3 = new QLabel("密码:",this);
lab3->resize(lab2->size());
lab3->move(130,190);
lab3->setPixmap(QPixmap("D:\\QT\\hqyj\\QT\\icon\\denglumima.png"));
lab3->setScaledContents(true);
edit1 = new QLineEdit(this);
edit1->resize(200,30);
edit1->move(190,160);
//edit1->setStyleSheet("border:none;");
edit1->setPlaceholderText("QQ号/微信/邮箱");
edit2 = new QLineEdit("密码",this);
edit2->resize(edit1->size());
edit2->move(190,200);
edit2->setPlaceholderText("密码");
edit2->setEchoMode(QLineEdit::Password);
//登录按钮
QPushButton *btn1 = new QPushButton;
btn1->setParent(this);
btn1->setText("登录");
btn1->resize(90,30);
btn1->move(220,240);
btn1->setIcon(QIcon("D:\\QT\\hqyj\\QT\\icon\\denglu_1.png"));
connect(btn1,SIGNAL(clicked()),this,SLOT(btn1_clicked()));
//取消按钮
QPushButton *btn3 = new QPushButton("取消",this);
btn3->resize(btn1->size());
btn3->move(220,280);
btn3->setIcon(QIcon("D:\\QT\\hqyj\\QT\\icon\\quxiao.png"));
connect(btn3,SIGNAL(clicked()),this,SLOT(close()));
}
void Widget::btn1_clicked()
{
if(edit1->text() == "admin" && edit2->text() == "123456")
{
qDebug() << "登录成功";
this->close();
emit jump();
}
else
{
qDebug() << "账号或密码错误";
}
}
Widget::~Widget()
{
}
new.cpp
#include "new.h"
#include "ui_new.h"
New::New(QWidget *parent) :
QWidget(parent),
ui(new Ui::New)
{
ui->setupUi(this);
}
New::~New()
{
delete ui;
}
//处理跳转信号函数对应的槽函数
void New::jump_slot()
{
this->show(); //将当前界面进行展示
}
main.cpp
#include "widget.h"
#include <QApplication>
#include "new.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
New n;
QObject::connect(&w,&Widget::jump,&n,&New::jump_slot);
return a.exec();
}