• day48


    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. s1=new second;
    9. connect(this,&Widget::jump,s1,&second::jump_slot);
    10. ui->lab1->setPixmap(QPixmap(":/tu/nsh.png"));
    11. ui->lab1->setScaledContents(true);
    12. ui->lab2->setPixmap(QPixmap(":/tu/zh.jpg"));
    13. ui->lab2->setScaledContents(true);
    14. ui->lab3->setPixmap(QPixmap(":/tu/mm.png"));
    15. ui->lab3->setScaledContents(true);
    16. if(!db.contains("mydatabase.db"))
    17. {
    18. db=QSqlDatabase::addDatabase("QSQLITE");
    19. db.setDatabaseName("mydatabase.db");
    20. }
    21. if(!db.open())
    22. {
    23. QMessageBox::information(this,"失败","数据库打开失败");
    24. return;
    25. }
    26. QString sql = "create table if not exists stu_info("
    27. "name integer primary key,"
    28. "password integer)";
    29. QSqlQuery querry;
    30. if(!querry.exec(sql))
    31. {
    32. QMessageBox::information(this,"失败","创建表失败");
    33. return;
    34. }
    35. }
    36. Widget::~Widget()
    37. {
    38. delete ui;
    39. }
    40. void Widget::on_buf1_clicked()
    41. {
    42. QString sql = "select * from stu_info where name";
    43. QString sq = "select * from stu_info where password";
    44. QSqlQuery querry;
    45. QSqlQuery quess;
    46. if(!querry.exec(sql))
    47. {
    48. QMessageBox::information(this,"提示","登录失败");
    49. return;
    50. }
    51. if(!quess.exec(sq))
    52. {
    53. QMessageBox::information(this,"提示","登录失败");
    54. return;
    55. }
    56. //遍历账号
    57. int i=0;
    58. while(querry.next()&&quess.next())
    59. {
    60. //判断
    61. if(ui->lin1->text()==querry.record().value(0).toString()&&ui->lin2->text()==quess.record().value(0).toString())
    62. {
    63. QMessageBox box(QMessageBox::Information,
    64. "信息对话框",
    65. "登录成功",
    66. QMessageBox::Ok,
    67. this);
    68. int ret = box.exec();
    69. if(ret == QMessageBox::Ok)
    70. {
    71. emit jump();
    72. this->close();
    73. }
    74. i=1;
    75. break;
    76. }
    77. }
    78. if(i==0)
    79. {
    80. QMessageBox box(QMessageBox::Warning,
    81. "错误对话框",
    82. "账号密码不匹配是否重新登录",
    83. QMessageBox::Ok|QMessageBox::Cancel,
    84. this);
    85. int ret = box.exec();
    86. if(ret == QMessageBox::Ok)
    87. {
    88. //清空密码
    89. ui->lin2->clear();
    90. }
    91. else if(ret == QMessageBox::Cancel)
    92. {
    93. this->close();
    94. }
    95. }
    96. }
    97. void Widget::on_buf2_clicked()
    98. {
    99. int ret=QMessageBox::question(this,
    100. "问题",
    101. "是否确认退出",
    102. QMessageBox::Yes|QMessageBox::No,
    103. QMessageBox::No);
    104. if(ret == QMessageBox::Yes)
    105. {
    106. this->close();
    107. }
    108. else if(ret==QMessageBox::No)
    109. {
    110. }
    111. }
    112. void Widget::on_buf3_clicked()
    113. {
    114. int name=ui->lin1->text().toUInt();
    115. int password=ui->lin2->text().toUInt();
    116. if(name==0||password==0)
    117. {
    118. QMessageBox::information(this,"提示","请将信息填写完整");
    119. return;
    120. }
    121. QString sql=QString("insert into stu_info(name,password)"
    122. "values(%1,%2)").arg(name).arg(password);
    123. QSqlQuery querry;
    124. if(!querry.exec(sql))
    125. {
    126. QMessageBox::information(this,"失败","添加失败");
    127. return;
    128. }else
    129. {
    130. QMessageBox::information(this,"成功","添加成功");
    131. }
    132. }

    widget.h

    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3. #include "second.h"
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. QT_BEGIN_NAMESPACE
    11. namespace Ui { class Widget; }
    12. QT_END_NAMESPACE
    13. class Widget : public QWidget
    14. {
    15. Q_OBJECT
    16. public:
    17. Widget(QWidget *parent = nullptr);
    18. ~Widget();
    19. signals:
    20. void jump();
    21. private slots:
    22. void on_buf1_clicked();
    23. void on_buf2_clicked();
    24. void on_buf3_clicked();
    25. private:
    26. Ui::Widget *ui;
    27. second *s1;
    28. QSqlDatabase db;
    29. };
    30. #endif // WIDGET_H

     

  • 相关阅读:
    TCP 的 Keepalive 和 HTTP 的 Keep-Alive 是一个东西吗?
    背包问题(动归)
    Outlook屏蔽Jira AI提醒
    NEFU离散数学实验2-容斥原理
    阿里云张建锋:云计算变革被严重低估,新型计算体系正在到来
    Tkinter学习笔记(一):完成文件选择和保存对话框
    Ubuntu下目标检测YOLO系列网络安装OpenCV时Darknet编译出现的问题(pjreddie版本)
    Yaml文件浅讲
    猿创征文|基于libevet的C++高并发、易扩展HTTP服务迭代之路
    Llama2-Chinese项目:2.2-大语言模型词表扩充
  • 原文地址:https://blog.csdn.net/weixin_69452640/article/details/133148228