创建一个登录窗口

 head.h

#ifndef FIRST01WND_H
#define FIRST01WND_H

#include <QMainWindow>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class first01wnd; }
QT_END_NAMESPACE

class first01wnd : public QMainWindow
{
    Q_OBJECT
signals:

private slots:
    void loginbtn_clicked_slots();
    void logoutbtn_clicked_slots();
public:
    first01wnd(QWidget *parent = nullptr);
    ~first01wnd();


private:
    Ui::first01wnd *ui;
    QLabel *label1;
    QLabel *label_account;
    QLabel *label_password;
    QLineEdit *edit_account;
    QLineEdit *edit_password;
    QPushButton *pushbtn_login;
    QPushButton *pushbtn_logout;
};
#endif // FIRST01WND_H

fun.cpp

#include "first01wnd.h"
#include "ui_first01wnd.h"

first01wnd::first01wnd(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::first01wnd)
{
    ui->setupUi(this);
    this->setFixedSize(600,400);
    this->setWindowIcon(QIcon("D:/qt/2Q1e/icon/QQ.png"));
    this->setWindowTitle("QQ");

    label1 = new QLabel(this);
    label1->setPixmap(QPixmap("D:/qt/2Q1e/icon/logo.png"));
    label1->resize(600,200);
    label1->setScaledContents(true);

    label_account = new QLabel(this);
    label_account->resize(25,25);
    label_account->move(100,250);
    label_account->setScaledContents(true);
    label_account->setPixmap(QPixmap("D:/qt/2Q1e/icon/zhanghao.png"));



    label_password = new QLabel(this);
    label_password->resize(25,25);
    label_password->move(100,300);
    label_password->setScaledContents(true);
    label_password->setPixmap(QPixmap("D:/qt/2Q1e/icon/denglumima.png"));

    edit_account = new QLineEdit(this);
    edit_account->resize(150,25);
    edit_account->setPlaceholderText("账号/手机号/邮箱");
    edit_account->move(150,250);

    edit_password = new QLineEdit(this);
    edit_password->resize(150,25);
    edit_password->setPlaceholderText("密码");
    edit_password->setEchoMode(QLineEdit::Password);
    edit_password->move(150,300);

    pushbtn_login = new QPushButton(QString("登录"),this);
    pushbtn_login->resize(50,30);
    pushbtn_login->move(400,350);

    pushbtn_logout = new QPushButton(QString("退出"),this);
    pushbtn_logout->resize(50,30);
    pushbtn_logout->move(480,350);

    this->connect(pushbtn_login,SIGNAL(clicked()),this,SLOT(loginbtn_clicked_slots()));
    this->connect(pushbtn_logout,SIGNAL(clicked()),this,SLOT(logoutbtn_clicked_slots()));

}

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


void first01wnd:: loginbtn_clicked_slots()
{
    QString account_text = this->edit_account->text();
    QString password_text = this->edit_password->text();
    if((account_text == "admin" ) && (password_text == "123456") )
    {
         qDebug()<<"登录成功";
         close();
    }
    else
    {
        qDebug()<<"用户名与密码不匹配";
        this->edit_password->clear();
    }
}

void first01wnd:: logoutbtn_clicked_slots()
{
    close();
}

main.cpp

#include "first01wnd.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    first01wnd w;
    w.show();
    return a.exec();
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值