• 2023年9月18日


    完善登录框

    点击登录按钮后,判断账号(admin)和密码(123456)是否一致,如果匹配失败,则弹出错误对话框,文本内容“账号密码不匹配,是否重新登录”,给定两个按钮ok和cancel,点击ok后,会清除密码框中的内容,继续进行登录;如果点击cancel按钮,则关闭界面。

    如果账号和密码匹配,则弹出信息对话框,给出提示信息为“登录成功”,给出一个按钮ok,点击ok后,关闭整个登录界面,跳转到其他界面

    点击取消按钮后,弹出问题对话框,询问是否确定要退出登录,给出两个按钮,yes|no,点击yes,则直接关闭整个登录界面,如果点击no则进行进行登录

    要求:消息对话框,对象版和静态成员函数版至少各实现一个

    mainwindow.h

    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. QT_BEGIN_NAMESPACE
    11. namespace Ui {class MainWindow;}
    12. QT_END_NAMESPACE
    13. class MainWindow : public QMainWindow
    14. {
    15. Q_OBJECT
    16. public:
    17. MainWindow(QWidget *parent = nullptr);
    18. ~MainWindow();
    19. public slots:
    20. //void on_btn1_clicked();
    21. void my_slot1();
    22. private:
    23. Ui::MainWindow *ui;
    24. QLineEdit *edti1;
    25. QLineEdit *edti2;
    26. QPushButton *btn1;
    27. QPushButton *btn2;
    28. QLabel *lab1;
    29. QLabel *lab2;
    30. QLabel *lab3;
    31. signals:
    32. void btn1_signal();
    33. void jump();
    34. };
    35. #endif // MAINWINDOW_H

    second.h

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

    main.cpp

    1. #include "mainwindow.h"
    2. #include "second.h"
    3. #include
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. second s;
    10. QObject::connect(&w,&MainWindow::jump,&s,&second::jump_slot);
    11. return a.exec();
    12. }

    mainwindow.cpp

    1. #include "mainwindow.h"
    2. #include
    3. #include
    4. #include
    5. #include
    6. MainWindow::MainWindow(QWidget *parent)
    7. : QMainWindow(parent)
    8. {
    9. //界面
    10. this->setFixedSize(800,600); //设置固定尺寸
    11. this->setWindowTitle("摇篮游行"); //设置窗口标签
    12. this->setWindowIcon(QIcon(":/pict/123.webp")); //设置窗口图标
    13. //按钮
    14. btn1 = new QPushButton(QIcon(":/pict/213.jpg"),"登录",this); //构造一个按钮
    15. btn1->resize(100,50); //设置按钮大小
    16. btn1->move(550,420); //移动按钮
    17. btn2 = new QPushButton(QIcon(":/pict/12345.jpg"),"退出",this); //构造一个按钮
    18. btn2->resize(btn1->size());
    19. btn2->move(550,520);
    20. //行编辑器
    21. edti1 = new QLineEdit(this); //构造一个行编辑器
    22. edti1->setPlaceholderText("繁星凝望着海洋");
    23. edti1->resize(300,50);
    24. edti1->move(180,420);
    25. edti2 = new QLineEdit(this); //构造一个行编辑器
    26. edti2->setPlaceholderText("海洋拥抱着风帆");
    27. edti2->resize(300,50);
    28. edti2->move(180,520);
    29. //按钮1事件
    30. connect(btn1,SIGNAL(clicked()),this,SLOT(my_slot1()));
    31. //标签
    32. lab1 = new QLabel(this);
    33. lab1->resize(80,50);
    34. lab1->setPixmap(QPixmap(":/pict/321.webp"));
    35. lab1->setScaledContents(true);
    36. lab1->move(100,420);
    37. lab2 = new QLabel(this);
    38. lab2->resize(80,50);
    39. lab2->setPixmap(QPixmap(":/pict/4321.webp"));
    40. lab2->setScaledContents(true);
    41. lab2->move(100,520);
    42. //gif
    43. QMovie *movie = new QMovie(":/pict/6.gif");
    44. lab3 = new QLabel(this);
    45. lab3->resize(800,400);
    46. lab3->setMovie(movie);
    47. movie->start();
    48. lab3->setScaledContents(true);
    49. lab3->move(0,0);
    50. }
    51. void MainWindow::my_slot1()
    52. {
    53. QMessageBox msgbox;
    54. if(edti1->text()=="admin"&&edti2->text()=="123456")
    55. {
    56. QMessageBox msgbox(QMessageBox::Information,
    57. "摇篮夜行",
    58. "登录成功",
    59. QMessageBox::Ok,
    60. this);
    61. emit jump();
    62. this->close();
    63. }else
    64. {
    65. int ret = QMessageBox::critical(
    66. this,tr("摇篮夜行"),
    67. tr("账号或密码不正确,是否重新登录"),
    68. QMessageBox::Yes | QMessageBox::Cancel,
    69. QMessageBox::Cancel
    70. );
    71. if(ret == QMessageBox::Cancel)
    72. {
    73. int ret2 = QMessageBox::question(
    74. this,
    75. tr("摇篮夜行"),
    76. tr("是否退出"),
    77. QMessageBox::Yes | QMessageBox::No,
    78. QMessageBox::No
    79. );
    80. if(ret2 == QMessageBox::Yes)
    81. {
    82. this->close();
    83. }
    84. }
    85. this->edti1->clear();
    86. this->edti2->clear();
    87. }
    88. }
    89. MainWindow::~MainWindow()
    90. {
    91. }

    second.cpp

    1. #include "second.h"
    2. #include "ui_second.h"
    3. second::second(QWidget *parent) :
    4. QWidget(parent),
    5. ui(new Ui::second)
    6. {
    7. ui->setupUi(this);
    8. }
    9. second::~second()
    10. {
    11. delete ui;
    12. }
    13. void second::jump_slot()
    14. {
    15. this->show();
    16. }

  • 相关阅读:
    python爬虫中怎么写反爬虫
    【ACWing】123. 士兵
    【luogu P7518】宝石(主席树)(二分)
    MAX/MSP SDK学习05:A_GIMME方法
    基于群智能的路径规划算法(二)------蚁群算法
    mac通过docker搭建elasticsearch:8.9.2以及kibana:8.9.2
    前端使用 Konva 实现可视化设计器(10)- 对齐线
    认证学习3 - Digest摘要认证讲解、代码实现、演示
    【python】爬虫异步网络请求探索async+request与async+aiohttp
    网络空间内生安全数学基础(1)——背景
  • 原文地址:https://blog.csdn.net/2201_75732711/article/details/132996645