• C++DAY48


     

     

    second.h

    1. #ifndef SECOND_H
    2. #define SECOND_H
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. namespace Ui {
    11. class second;
    12. }
    13. class second : public QWidget
    14. {
    15. Q_OBJECT
    16. public:
    17. explicit second(QWidget *parent = nullptr);
    18. ~second();
    19. public slots:
    20. void jumpSlot();//对应第一个窗口信号的槽函数声明
    21. private:
    22. Ui::second *ui;
    23. };
    24. #endif // SECOND_H

    widget

    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. QT_BEGIN_NAMESPACE
    10. namespace Ui { class Widget; }
    11. QT_END_NAMESPACE
    12. class Widget : public QWidget
    13. {
    14. Q_OBJECT
    15. public:
    16. Widget(QWidget *parent = nullptr);
    17. ~Widget();
    18. signals:
    19. void jump(); //自定义一个跳转信号
    20. public slots:
    21. void my_slot();
    22. void my_on();
    23. private:
    24. Ui::Widget *ui;
    25. };
    26. #endif // WIDGET_H

    mian.cpp

    1. #include "widget.h"
    2. #include "second.h"
    3. #include
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Widget w;
    8. w.show();
    9. //实例化第二个窗口的对象
    10. second s;
    11. //将一个窗口的jump信号和第二窗口的jumpSlot槽函数连接
    12. QObject::connect(&w, &Widget::jump, &s, &second::jumpSlot);
    13. return a.exec();
    14. }

    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. this->setWindowTitle("300英雄");//设置窗口标题
    9. this->setWindowIcon(QIcon(":/pic/1.png"));//设置窗口图片
    10. QMovie *mv = new QMovie(":/pic/93.gif");//设置图片
    11. ui->label->setMovie(mv);
    12. mv->start();
    13. ui->label->setScaledContents(true);//让图自动使用标签
    14. }
    15. second::~second()
    16. {
    17. delete ui;
    18. }
    19. void second::jumpSlot()
    20. {
    21. this->show();
    22. }

    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->setWindowTitle("300英雄");//设置窗口标题
    9. this->setWindowIcon(QIcon(":/pic/1.png"));//设置窗口图片
    10. ui->label1->setPixmap(QPixmap(":/pic/65.jpg"));//设置图片
    11. ui->label1->setScaledContents(true);//让图自动使用标签
    12. ui->label2->setPixmap(QPixmap(":/pic/5.jpg"));//设置图片
    13. ui->label2->setScaledContents(true);//让图自动使用标签
    14. ui->label3->setPixmap(QPixmap(":/pic/6.jpg"));//设置图片
    15. ui->label3->setScaledContents(true);//让图自动使用标签
    16. ui->label4->setPixmap(QPixmap(":/pic/a.gif"));//设置图片
    17. ui->label4->setScaledContents(true);//让图自动使用标签
    18. ui->username->setPlaceholderText("账号");
    19. ui->password->setPlaceholderText("密码");
    20. ui->password->setEchoMode(QLineEdit::Password);
    21. this->connect(ui->Btn2,SIGNAL(clicked()),this,SLOT(my_slot()));
    22. connect(ui->Btn1,&QPushButton::clicked,this,&Widget::my_on);
    23. }
    24. Widget::~Widget()
    25. {
    26. delete ui;
    27. }
    28. void Widget::my_slot()
    29. {
    30. int ret = QMessageBox::question(this,
    31. "300英雄",//对话框标题
    32. "您是否确定要退出登录?",//对话框文本
    33. QMessageBox::Yes | QMessageBox::No);//提供按钮
    34. if(ret == QMessageBox::Yes)//对用户选中的按钮进行判断
    35. {
    36. this->close();//关闭界面
    37. }
    38. }
    39. void Widget::my_on()
    40. {
    41. if(ui->username->text() == "admin")//账号正确
    42. {
    43. if(ui->password->text() == "123456")//密码正确
    44. {
    45. int ret = QMessageBox::information(this,//直接调用静态成员函数
    46. "300英雄",//对话框标题
    47. "登录成功",//对话框文本
    48. QMessageBox::Ok);//提供按钮
    49. if(QMessageBox::Ok == ret)
    50. {
    51. this->close();//关闭界面
    52. emit jump();//登录成功跳转
    53. }
    54. }
    55. else
    56. {
    57. QMessageBox msg(
    58. QMessageBox::Warning, //图标
    59. "300英雄", //对话框标题
    60. "账号和密码不匹配,是否重新登录", //对话框文本
    61. QMessageBox::Yes | QMessageBox::No, //提供按钮
    62. this);
    63. int ret = msg.exec(); //用exec()函数执行对话框
    64. if(ret == QMessageBox::Yes)//对用户选中的按钮进行判断
    65. {
    66. ui->password->clear();//清空密码框中的内容
    67. }
    68. else
    69. {
    70. this->close();//关闭界面
    71. }
    72. }
    73. }
    74. else
    75. {
    76. QMessageBox msg(
    77. QMessageBox::Warning, //图标
    78. "300英雄", //对话框标题
    79. "账号和密码不匹配,是否重新登录", //对话框文本
    80. QMessageBox::Yes | QMessageBox::No, //提供按钮
    81. this);
    82. int ret = msg.exec();//用exec()函数执行对话框
    83. if(ret == QMessageBox::Yes)//对用户选中的按钮进行判断
    84. {
    85. ui->username->clear();//清空账号框中的内容
    86. ui->password->clear();//清空密码框中的内容
    87. }
    88. else
    89. {
    90. this->close();//关闭界面
    91. }
    92. }
    93. }

  • 相关阅读:
    阿里开源的32B大模型到底强在哪里?
    2023-10-03 LeetCode每日一题(买卖股票的最佳时机 III)
    神经网络理论及应用答案,神经网络的数学表达式
    优惠劵秒杀优化-分布式锁
    mysql数据库安装配置
    MySQL 篇-深入了解事务四大特性及原理
    百度地图发布2022国庆出行预测
    GET请求中传参List<String>的一些问题
    核方法总结(三)———核主成分(kernel PCA)学习笔记
    Vuex的使用
  • 原文地址:https://blog.csdn.net/weixin_69186714/article/details/133934581