完善登录界面 1>点击登录按钮后,判断账号(admin)和密码(123456)是否一致,如果匹配失败,则弹出错误对话框,文本内容“账号密码不匹配,是否重新登录”,给定两个按钮ok和cancel

widget.h 头函数

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QDebug>
#include<QMessageBox>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT
public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();


signals:
void btn1_signal();

public slots:
void btn1_slot();
void btn2_slot();



private:
    Ui::Widget *ui;
    QPushButton *btn1;
    QPushButton *btn2;
    QLineEdit *edit1;
    QLineEdit *edit2;
    QLabel *lab1;
    QLabel *lab2;
    QLabel *lab3;

};

#endif // WIDGET_H

second.h

#ifndef SECOND_H
#define SECOND_H

#include <QWidget>

namespace Ui {
class Second;
}

class Second : public QWidget
{
    Q_OBJECT

public:
    explicit Second(QWidget *parent = nullptr);
    ~Second();

private:
    Ui::Second *ui;

public slots:
    void btn1_jumpslot();

};

#endif // SECOND_H

main.cpp

#ifndef SECOND_H
#define SECOND_H

#include <QWidget>

namespace Ui {
class Second;
}

class Second : public QWidget
{
    Q_OBJECT

public:
    explicit Second(QWidget *parent = nullptr);
    ~Second();

private:
    Ui::Second *ui;

public slots:
    void btn1_jumpslot();

};

#endif // SECOND_H

 widget.cpp

#include "widget.h"
#include "ui_widget.h"

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

    //定义窗口
    this->setMaximumSize(800,530);
    this->setMinimumSize(800,530);
    this->setWindowIcon(QIcon("D:/Qt/icon_nhgbq8i4bf/QQ.png"));
    this->setWindowTitle("QQ");


    //定义展示数据
    QLabel *lab1 =new QLabel(this);
    lab1->resize(800,200);
    lab1->setStyleSheet("background-color:blue;");

    QLabel *lab2 =new QLabel(this);
    lab2->move(150,230);
    lab2->resize(80,60);
    lab2->setScaledContents(true);
    lab2->setPixmap(QPixmap("D:/Qt/icon_nhgbq8i4bf/denglu.png"));

    QLabel *lab3 =new QLabel(this);
    lab3->move(150,330);
    lab3->resize(80,60);
    lab3->setScaledContents(true);
    lab3->setPixmap(QPixmap("D:/Qt/icon_nhgbq8i4bf/denglumima.png"));

    //定义展示行编辑器
    QLineEdit *edit1 =new QLineEdit(this);
    edit1->move(250,230);
    edit1->resize(400,60);
    edit1->setPlaceholderText("QQ号码/手机号/邮箱");

    QLineEdit *edit2 =new QLineEdit(this);
    edit2->move(250,330);
    edit2->resize(400,60);
    edit2->setPlaceholderText("密码");
    edit2->setEchoMode(QLineEdit::Password);

    //定义展示按钮
    QPushButton *btn1 = new QPushButton;
    btn1->setParent(this);  //将该界面作为组件的父组件
    btn1->resize(200,80);
    btn1->setText("登录");
    btn1->move(150,420);
    btn1->setStyleSheet("background-color:blue;""border-radius:6px");

    QPushButton *btn2 = new QPushButton;
    btn2->setParent(this);  //将该界面作为组件的父组件
    btn2->resize(200,80);
    btn2->setText("取消");
    btn2->move(450,420);
    btn2->setStyleSheet("background-color:blue;""border-radius:6px");

    //QT4版手动连接buton1信号和槽
    connect(this->btn1,SIGNAL(clicked()),this,SLOT(but1_slot()));
    //QT5版手动连接button2信号和槽
  connect(this->btn2, &QPushButton::clicked, this, &Widget::btn2_slot);
}

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


void Widget::btn1_slot()
{
    QMessageBox msgbox;
    if(edit1->text()=="admin" &&edit2->text()=="123456")
    {
        msgbox.setIcon(QMessageBox::NoIcon);
                msgbox.setWindowTitle("QQ");
                msgbox.setText("登陆成功");
                msgbox.setStandardButtons(QMessageBox::Ok);
                msgbox.setDefaultButton(QMessageBox::Ok);
                msgbox.exec();
                emit btn1_signal();
                this->close();
    }
    else
    {
        QMessageBox msgBox;
          int ret;

          msgbox.setIcon(QMessageBox::Critical);
          msgbox.setWindowTitle("QQ");
          msgbox.setText("账号密码不匹配,是否重新登录?");
          msgbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
          msgbox.setDefaultButton(QMessageBox::Ok);
          ret = msgBox.exec();
          if(ret == QMessageBox::Ok)
          {
                edit2->clear();
          }
           else if(ret == QMessageBox::Cancel)
          {
                msgbox.close();
          }
    }
 }

void Widget::btn2_slot()
{
    QMessageBox::StandardButton ret = QMessageBox::warning(             //调用静态成员函数,需要加上类名和作用域限定符
                                                   this,                    //父组件
                                                   "QQ",                  //对话框标题
                                                   "是否确定退出登录?",        //对话框文本内容
                                                   QMessageBox::Yes|QMessageBox::No,   //提供的按钮
                                                   QMessageBox::Yes);                  //默认按钮


      //对用户点击的结果进行判断
      if(ret == QMessageBox::No)
      {
          this->close();
      }
}

second.cpp

#include "second.h"
#include "ui_second.h"

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

    //窗口属性
        this->setFixedSize(480,360);
        this->setWindowTitle("网络聊天室");

}

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

void Second::btn1_jumpslot()
{
    this->show();
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值