• 华清 Qt day2 9月18


    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. #include "second.h"
    12. QT_BEGIN_NAMESPACE
    13. namespace Ui { class Widget; }
    14. QT_END_NAMESPACE
    15. class Widget : public QWidget
    16. {
    17. Q_OBJECT
    18. public:
    19. Widget(QWidget *parent = nullptr);
    20. ~Widget();
    21. private slots:
    22. void on_btn1_clicked();
    23. void on_btn2_clicked();
    24. void on_le1_cursorPositionChanged(int arg1, int arg2);
    25. void on_le2_cursorPositionChanged(int arg1, int arg2);
    26. signals:
    27. void jump();
    28. private:
    29. Ui::Widget *ui;
    30. Second *s1;
    31. };
    32. #endif // WIDGET_H
    1. #ifndef SECOND_H
    2. #define SECOND_H
    3. #include
    4. namespace Ui {
    5. class Second;
    6. }
    7. class Second : public QDialog
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit Second(QWidget *parent = nullptr);
    12. ~Second();
    13. public slots:
    14. void jump_slot();
    15. private:
    16. Ui::Second *ui;
    17. };
    18. #endif // SECOND_H
    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. s1 = new Second;
    9. }
    10. Widget::~Widget()
    11. {
    12. delete ui;
    13. }
    14. //登录按钮
    15. void Widget::on_btn1_clicked()
    16. {
    17. QString username = ui->le1->text();
    18. QString password = ui->le2->text();
    19. //登录成功
    20. if(username=="admin" && password=="123456")
    21. {
    22. QMessageBox::information(this,"登录成功","登录成功");
    23. //跳转到其他界面的代码
    24. connect(this,&Widget::jump,s1,&Second::jump_slot);
    25. emit jump();
    26. this->hide();
    27. }
    28. else //登录失败
    29. {
    30. //静态版
    31. int ret = QMessageBox::critical(this,"登录失败",
    32. "账号密码不匹配,是否重新登录",
    33. QMessageBox::Ok|QMessageBox::Cancel);
    34. if(ret==QMessageBox::Ok)
    35. {
    36. //清楚密码框内容
    37. ui->le2->clear();
    38. }
    39. else if(ret==QMessageBox::Cancel)
    40. {
    41. //关闭界面
    42. close();
    43. }
    44. }
    45. }
    46. //取消按钮
    47. void Widget::on_btn2_clicked()
    48. {
    49. //对象版
    50. QMessageBox box(QMessageBox::Question,"退出登录","是否确定退出登录?",
    51. QMessageBox::Yes|QMessageBox::No,
    52. this);
    53. int ret = box.exec();
    54. if(ret == QMessageBox::Yes)
    55. {
    56. //关闭界面
    57. close();
    58. }
    59. }
    60. //输入账号
    61. void Widget::on_le1_cursorPositionChanged(int arg1, int arg2)
    62. {
    63. ui->le1->setPlaceholderText("账号");
    64. }
    65. //输入密码
    66. void Widget::on_le2_cursorPositionChanged(int arg1, int arg2)
    67. {
    68. ui->le2->setPlaceholderText("密码");
    69. ui->le2->setEchoMode(QLineEdit::Password);
    70. ui->le2->setMaxLength(7);
    71. }
    1. #include "second.h"
    2. #include "ui_second.h"
    3. Second::Second(QWidget *parent) :
    4. QDialog(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. }
    1. #include "widget.h"
    2. #include
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. Widget w;
    7. w.show();
    8. return a.exec();
    9. }

     

     

     在线思维导图 - GitMind

  • 相关阅读:
    全新升级的AOP框架Dora.Interception[6]: 框架设计和实现原理
    这是一个隐藏的(绝世武功)Java 学习路线图,祝你Offer拿到手软
    python小知识
    Jetpack Compose - Button按钮使用
    【Linux】进程状态详解
    Java类和对象:类是对象的模板,对象是类的实例化
    【C进阶】之结构体类型( struct)
    高维数组是如何通过底层连续存储实现的?
    运动控制卡应用开发教程之调用激光振镜控制
    计算机毕业设计 SSM餐饮收银管理系统 商场收银系统 饭店收银系统 服装店收银系统
  • 原文地址:https://blog.csdn.net/Huxiao1220/article/details/132996001