• QT day3


    思维导图

    编程题

    完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示”登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面
    如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面
    如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes|No,用户迪纳基Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
    要求:基于属性版和基于静态成员函数版至少各用一个

    第一个界面

    widget.h

    1. #define WIDGET_H
    2. #include
    3. #include
    4. QT_BEGIN_NAMESPACE
    5. namespace Ui { class Widget; }
    6. QT_END_NAMESPACE
    7. class Widget : public QWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. Widget(QWidget *parent = nullptr);
    12. ~Widget();
    13. signals:
    14. void my_jump();
    15. private slots:
    16. void on_pushButton_clicked();
    17. void on_exitBtn_clicked();
    18. private:
    19. Ui::Widget *ui;
    20. };
    21. #endif // WIDGET_H

    widget.cpp

    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. Widget::Widget(QWidget *parent)
    4. : QWidget(parent)
    5. , ui(new Ui::Widget)
    6. {
    7. ui->setupUi(this);
    8. this->setWindowFlag(Qt::FramelessWindowHint);
    9. this->setAttribute(Qt::WA_TranslucentBackground); //去掉空白部分
    10. }
    11. Widget::~Widget()
    12. {
    13. delete ui;
    14. }
    15. void Widget::on_pushButton_clicked()
    16. {
    17. if(ui->userEdi->text() == "admin" & ui->passwordEdit->text() == "123456")
    18. {
    19. //弹出成功登录的对话框
    20. QMessageBox msg(QMessageBox::Information,"提示","登录成功",QMessageBox::Ok,this);
    21. //显示对话框
    22. int ret = msg.exec();
    23. if(ret == QMessageBox::Ok)
    24. {
    25. //如果点击ok按钮,则关闭登陆界面 跳转到第二界面
    26. this->close();
    27. emit my_jump();
    28. }
    29. }
    30. else
    31. {
    32. //密码输入错误 输出错误对话框
    33. //调用静态成员函数 弹出对话框
    34. int ret = QMessageBox::critical(this,"提示","账号和密码不匹配,是否重新登录",QMessageBox::Yes | QMessageBox::No);
    35. //如果用户点击yes,清除密码框里的内容
    36. if(ret == QMessageBox::Yes)
    37. {
    38. ui->passwordEdit->clear();
    39. }
    40. else //如果用户点击no,直接关闭登陆界面
    41. {
    42. this->close();
    43. }
    44. }
    45. }
    46. void Widget::on_exitBtn_clicked()
    47. {
    48. //如果用户点击取消按钮 弹出问题对话框
    49. int ret = QMessageBox::question(this,"?","您确定要退出登录吗?",QMessageBox::Yes | QMessageBox::No);
    50. //如果点击yes 关闭登录界面
    51. if(ret == QMessageBox::Yes)
    52. {
    53. this->close();
    54. }
    55. }

    第二个界面:

    sencond.h

    1. #ifndef SENCOND_H
    2. #define SENCOND_H
    3. #include
    4. namespace Ui {
    5. class Sencond;
    6. }
    7. class Sencond : public QWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit Sencond(QWidget *parent = nullptr);
    12. ~Sencond();
    13. public slots:
    14. void my_jump_slot();
    15. private:
    16. Ui::Sencond *ui;
    17. };
    18. #endif // SENCOND_H

    sencond.cpp

    1. #include "sencond.h"
    2. #include "ui_sencond.h"
    3. Sencond::Sencond(QWidget *parent) :
    4. QWidget(parent),
    5. ui(new Ui::Sencond)
    6. {
    7. ui->setupUi(this);
    8. }
    9. Sencond::~Sencond()
    10. {
    11. delete ui;
    12. }
    13. void Sencond::my_jump_slot()
    14. {
    15. //显示界面
    16. this->show();
    17. }

    main.cpp

    1. #include "sencond.h"
    2. #include "ui_sencond.h"
    3. Sencond::Sencond(QWidget *parent) :
    4. QWidget(parent),
    5. ui(new Ui::Sencond)
    6. {
    7. ui->setupUi(this);
    8. }
    9. Sencond::~Sencond()
    10. {
    11. delete ui;
    12. }
    13. void Sencond::my_jump_slot()
    14. {
    15. //显示界面
    16. this->show();
    17. }

  • 相关阅读:
    什么是网络编程
    Qt系列-QSplitter使用笔记
    lightgbm使用multiclass训练二分类模型
    Flutter 使用FFI+CustomPainter实现全平台渲染视频
    【计算机网络三】数据链路层
    Scala中类的继承、抽象类和特质
    JUC原子类: CAS, Unsafe、CAS缺点、ABA问题如何解决详解
    webpack常见的loader和plugins,及它们各自作用机制
    (C++)线程同步——互斥对象
    mNetAssist(arm64)linux下图形界面的网络调试助手
  • 原文地址:https://blog.csdn.net/yuanruizhi123/article/details/136242790