Qt day2

实现登录框中,当登录成功时,关闭登录界面,并跳转到其他界面。
widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include <QIcon>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowIcon(QIcon("D:/QTProj/C++/icon/QQ.png"));
    setWindowTitle("Login");
    setFixedSize(500,400);
    QLabel *labLogo = new QLabel(this);
    labLogo->resize(500,150);
    labLogo->setPixmap(QPixmap("D:/QTProj/C++/icon/logo.jpg"));
    labLogo->setScaledContents(true);
    QLabel *labAccount = new QLabel(this);
    labAccount->resize(50,50);
    labAccount->setPixmap(QPixmap("D:/QTProj/C++/icon/denglu.png"));
    labAccount->setScaledContents(true);
    labAccount->move(100,200);
    QLabel *labPassword = new QLabel(this);
    labPassword->resize(50,50);
    labPassword->setPixmap(QPixmap("D:/QTProj/C++/icon/denglumima.png"));
    labPassword->setScaledContents(true);
    labPassword->move(100,280);
    QLineEdit *editAccount = new QLineEdit(this);
    editAccount->resize(200,50);
    editAccount->move(180,200);
    editAccount->setPlaceholderText("账号");
    QLineEdit *editPassword = new QLineEdit(this);
    editPassword->resize(200,50);
    editPassword->move(180,280);
    editPassword->setPlaceholderText("密码");
    editPassword->setEchoMode(QLineEdit::Password);
    QPushButton* btnLogin = new QPushButton("登录",this);
    btnLogin->setIcon(QIcon("D:/QTProj/C++/icon/denglu_1.png"));
    btnLogin->resize(100,50);
    btnLogin->move(250,340);
    QPushButton* btnCancel = new QPushButton("取消",this);
    btnCancel->setIcon(QIcon("D:/QTProj/C++/icon/quxiao.png"));
    btnCancel->resize(100,50);
    btnCancel->move(380,340);
    connect(btnLogin,&QPushButton::clicked,[=](){
        if(editAccount->text()=="admin"&&editPassword->text()=="123456"){
            emit toMainWindow();
            close();
        }else {
            qDebug()<<"登录失败";
        }
    });
}

Widget::~Widget()
{
    delete ui;
}


mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>

namespace Ui {
class MainWindow;
}

class MainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
public slots:
    void mainWindow_slot();
private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

MainWindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::mainWindow_slot()
{
    show();
}

Main.cpp

#include "widget.h"
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    MainWindow mw;
    QObject::connect(&w,&Widget::toMainWindow,&mw,&MainWindow::mainWindow_slot);
    return a.exec();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值